IntelliJ Java IDE
The moose likes Swing / AWT / SWT / JFace and the fly likes Swing elements not displaying properly Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Swing elements not displaying properly" Watch "Swing elements not displaying properly" New topic
Author

Swing elements not displaying properly

Scott Randel
Greenhorn

Joined: Feb 03, 2012
Posts: 2
Hello! I am new to Java, having taken an online course in it. I am trying to write a very simple program. I'm starting with the UI. I have four elements: a label, a combo box, another label, and a button. When I run the program, I see the second label (element #3) followed by the combo box (element #2). The other elements do not display. I have not set a layout (I have tried a couple, but I am obviously doing it wrong as I get errors.) The relevant code is quoted here (do I need to include more?) and a picture of the app's display is attached. Are my mistakes obvious to anybody?

Thanks for any help you can give me, folks!

JLabel label1 = new JLabel();
label1.setText("Select number of players:");
panel1.add(label1);

String[] possiblePlayers = {"1", "2", "3", "4"};
JComboBox combo1 = new JComboBox(possiblePlayers);
combo1.setSelectedIndex(1); // Set default number of players to 2
panel1.add(combo1);

JLabel label2 = new JLabel();
label1.setText("Click to Continue:");
panel1.add(label2);

JButton button1 = new JButton();
button1.setText("Proceed");
panel1.add(button1);
[Thumb - Swing display error.jpg]
 Filename Swing display error.jpg [Disk] Download
 Description
 Filesize 36 Kbytes
 Downloaded:  1 time(s)

Scott Randel
Greenhorn

Joined: Feb 03, 2012
Posts: 2
OK, I found and fixed the error in the code for label2.
 
IntelliJ Java IDE
 
subject: Swing elements not displaying properly
 
Threads others viewed
MY LOTTERY CLASS
executable jar file
TEXTFIELDS TO INT
jmenubar,menuitem
Problem with gridbaglayout in JPanel
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture