JButton -> erst sichtbar nach rollover

Status
Nicht offen für weitere Antworten.

RapiM

Mitglied
Hallo allerseits,

habe ein kleines Problem mit meinem Script! Der Button wird nur angezeigt, wenn ich drüber scrollen! Vorher leider nicht!

Liegt es irgendwie an der Reihenfolge? Wenn ich das ImageIcon auskommentiere, dann ist der Button ganz normal zu sehen!!!

Code:
 protected void buildUI() {
        int width = DisplaySystem.getDisplaySystem().getWidth();
        int height = DisplaySystem.getDisplaySystem().getHeight();

        //main box, which is centered
          JPanel main = new JPanel();
          main.setSize(1024, 768);
          main.setLocation(width/2 - main.getWidth()/2, height/2 - main.getHeight()/2);
          main.setOpaque(false);
          main.setVisible(true);
          
          getDesktop().getJDesktop().add(main);
          
          ImagePanel panel2 = new ImagePanel(new  ImageIcon(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "mainmenu_bg.png")).getImage());
          panel2.setSize(1024, 768);
          panel2.setLocation(width/2 - main.getWidth()/2, height/2 - main.getHeight()/2);
          
          getDesktop().getJDesktop().add(panel2);
          panel2.setVisible(true);
       
        
          
          //main_top
          JPanel main_top = new JPanel();
          main_top.setSize(1024, 300);
          main_top.setOpaque(false);
          main_top.setLocation(0, 0);
          main_top.setVisible(true);
          
          //main_center
          JPanel main_center = new JPanel();
          main_center.setSize(1024, 478);
          main_center.setOpaque(false);
          main_center.setLocation(0, 100);
          main_center.setVisible(true);
          
         
          JButton start_bb = new JButton("Spiel mit Balance Board starten");
          start_bb.setIcon(new ImageIcon(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "spiel_mit_bb_normal.png").getFile()));
          start_bb.setSize(280, 63);
          start_bb.setLocation(400, 290);
          start_bb.setRolloverIcon(new ImageIcon(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "spiel_mit_bb_over.png").getFile()));
          start_bb.setRolloverEnabled(true);
          start_bb.setVisible(true);
         
              
          
          //attach all to main
          main_center.add(start_bb);
          main.add(main_top);
          main.add(main_center);
          main.add(main_bottom);

Jemand eine Idee warum das so ist und wie ich das lösen kann?
Danke schonmal,
RapiM
 
setVisible(true) auf das Frame als letztes aufrufen, alle anderen setVisible(true) kannst du dir auch sparen,
wenn du erst im laufenden Programm neue Panel hinzufügst, dann evtl. validate()
 
hab doch noch eine Frage...

Code:
 protected void buildUI() {
        int width = DisplaySystem.getDisplaySystem().getWidth();
        int height = DisplaySystem.getDisplaySystem().getHeight();

          //main box, which is centered
          JPanel main = new JPanel();
          main.setSize(1024, 768);
          main.setLocation(width/2 - main.getWidth()/2, height/2 - main.getHeight()/2);
          main.setOpaque(false);

          getDesktop().getJDesktop().add(main);

          
          ImagePanel panel2 = new ImagePanel(new ImageIcon(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "mainmenu_bg.png")).getImage());
          panel2.setSize(1024, 768);
          panel2.setLocation(width/2 - main.getWidth()/2, height/2 - main.getHeight()/2);
          
          getDesktop().getJDesktop().add(panel2);
          panel2.setVisible(true);
          
         
          JButton start_bb = new JButton();
          start_bb.setIcon(new ImageIcon(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "spiel_mit_bb_normal.png").getFile()));
          start_bb.setSize(260, 63);
          start_bb.setLocation(400,400);
          
          start_bb.setBorderPainted(false);
          start_bb.setOpaque(false);
          start_bb.setRolloverIcon(new ImageIcon(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "spiel_mit_bb_over.png").getFile()));
          start_bb.setRolloverEnabled(true);
         
          
          
          //attach all to main
         main.add(start_bb);
          main.validate();
          
          main.setVisible(true);

Hab das nun so gemacht! Problem ist, dass start_bb immer oben in der Mitte hängen bleibt! Egal welche .setLocation() ich ihm gebe!!! Ich würde ihn gerne tiefer setzen!

Danke...
 
also wenn ich main.setLayout(null) setze dann verschiebt er start_bbzwar nach unten, aber dann ist wieder das Problem, dass es nur sichtbar wird, wenn ich drüber scrollen! komisch komisch 🙁🙁
 
hast du es geschafft,
main.setLayout(null)
ganz ans Ende hinter
main.setVisible(true);
zu setzen?

main.setVisible(true);
soll doch der allerletzte Befehl sein..
 
was dein Programm insgesamt macht, kann ich nicht weiter erahnen,
bei mir funktionierts
Java:
public class TestGUI extends JFrame {

	public TestGUI() {
		buildUI();

		setSize(400, 300);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);

	}

	protected void buildUI() {
		// main box, which is centered
		JPanel main = new JPanel();
		main.setSize(1024, 768);
		main.setLocation(0,0);
		main.setOpaque(false);

		JButton start_bb = new JButton("Test");
		start_bb.setSize(260, 63);
		start_bb.setLocation(200, 200);

		start_bb.setBorderPainted(false);
		start_bb.setOpaque(false);
		start_bb.setRolloverEnabled(true);

		// attach all to main
		main.setLayout(null);
		main.add(start_bb);
		add(main);
	}

	public static void main(String[] args) {
		new TestGUI();
	}

}
 
Hallo SlaterB,

nun klappt es! Musste noch in der GameEngine ein zusätzliches Update aufrufen! Danke für deine super Hilfe!!!
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben