[Solved]Java GUI Problems.

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Martyj
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Thu Apr 23, 2009 11:23 am
Location: Ogden Utah
Contact:

[Solved]Java GUI Problems.

Post by Martyj »

I'm having a hard time with java. Mostly the Layouts. My problem is currently that I'm not getting my gui to show. Here is my source code

Code: Select all

package test2;

/**
 *
 * @author MartyJ
 */
import javax.swing.*;
public class Main {
    
    public JFrame frame;
    public JTextField userName;
    public JTextField xp;
    public JButton search;
    public JComboBox combo;
    public JComboBox page;
    public JComboBox page2;
    private JComboBox jComboBox4;
    private JLabel jLabel1;
    private JLabel jLabel10;
    private JLabel jLabel11;
    private JLabel jLabel12;
    private JLabel jLabel13;
    private JLabel jLabel14;
    private JLabel jLabel15;
    private JLabel jLabel16;
    private JLabel jLabel17;
    private JLabel jLabel18;
    private JLabel jLabel19;
    private JLabel jLabel2;
    private JLabel jLabel20;
    private JLabel jLabel21;
    private JLabel jLabel22;
    private JLabel jLabel23;
    private JLabel jLabel24;
    private JLabel jLabel25;
    private JLabel jLabel26;
    private JLabel jLabel27;
    private JLabel jLabel28;
    private JLabel jLabel29;
    private JLabel jLabel3;
    private JLabel jLabel30;
    private JLabel jLabel31;
    private JLabel jLabel32;
    private JLabel jLabel33;
    private JLabel jLabel34;
    private JLabel jLabel35;
    private JLabel jLabel36;
    private JLabel jLabel37;
    private JLabel jLabel38;
    private JLabel jLabel39;
    private JLabel jLabel4;
    private JLabel jLabel40;
    private JLabel jLabel41;
    private JLabel jLabel42;
    private JLabel jLabel43;
    private JLabel jLabel44;
    private JLabel jLabel5;
    private JLabel jLabel6;
    private JLabel jLabel7;
    private JLabel jLabel8;
    private JLabel jLabel9;
    private JPanel mainPanel;
    private JButton jButton1;
    private JComboBox jComboBox1;
    private JComboBox jComboBox2;
    private JComboBox jComboBox3;
    private JTextField jTextField1;
    private JTextField jTextField2;
    
    public Main() {
        initComponents();
    }
     
    public static void main(String[] args){
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main();
            }
        });   
    }
    private void initComponents() {
        mainPanel = new JPanel();
        jButton1 = new JButton();
        jComboBox1 = new JComboBox();
        jComboBox2 = new JComboBox();
        jComboBox3 = new JComboBox();
        jTextField1 = new JTextField();
        jTextField2 = new JTextField();
        jLabel1 = new JLabel();
        jLabel2 = new JLabel();
        jLabel3 = new JLabel();
        jLabel4 = new JLabel();
        jLabel5 = new JLabel();
        jLabel6 = new JLabel();
        jLabel7 = new JLabel();
        jLabel8 = new JLabel();
        jLabel9 = new JLabel();
        jLabel10 = new JLabel();
        jLabel11 = new JLabel();
        jLabel12 = new JLabel();
        jLabel13 = new JLabel();
        jLabel14 = new JLabel();
        jLabel15 = new JLabel();
        jLabel16 = new JLabel();
        jLabel17 = new JLabel();
        jLabel18 = new JLabel();
        jLabel19 = new JLabel();
        jLabel20 = new JLabel();
        jLabel21 = new JLabel();
        jLabel22 = new JLabel();
        jLabel23 = new JLabel();
        jLabel24 = new JLabel();
        jLabel25 = new JLabel();
        jLabel26 = new JLabel();
        jLabel27 = new JLabel();
        jLabel28 = new JLabel();
        jLabel29 = new JLabel();
        jLabel30 = new JLabel();
        jLabel31 = new JLabel();
        jLabel32 = new JLabel();
        jLabel33 = new JLabel();
        jLabel34 = new JLabel();
        jComboBox4 = new JComboBox();
        jLabel35 = new JLabel();
        jLabel36 = new JLabel();
        jLabel37 = new JLabel();
        jLabel38 = new JLabel();
        jLabel39 = new JLabel();
        jLabel40 = new JLabel();
        jLabel41 = new JLabel();
        jLabel42 = new JLabel();
        jLabel43 = new JLabel();
        jLabel44 = new JLabel();

        mainPanel.setMaximumSize(new java.awt.Dimension(500, 500));
        mainPanel.setName("mainPanel");
        
        jButton1.setText("jButton1.text");
        jButton1.setName("jButton1");

        jComboBox1.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.setName("jComboBox1");

        jComboBox2.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox2.setName("jComboBox2");

        jComboBox3.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox3.setName("jComboBox3");

        jTextField1.setText("jTextField1.text");
        jTextField1.setName("jTextField1");

        jTextField2.setText("jTextField2.text");
        jTextField2.setName("jTextField2");

        jLabel1.setText("jLabel1.text");
        jLabel1.setName("jLabel1");

        jLabel2.setText("jLabel2.text");
        jLabel2.setName("jLabel2");

        jLabel3.setText("jLabel3.text");
        jLabel3.setName("jLabel3");

        jLabel4.setText("jLabel4.text");
        jLabel4.setName("jLabel4");

        jLabel5.setText("jLabel5.text");
        jLabel5.setName("jLabel5");

        jLabel6.setText("jLabel6.text");
        jLabel6.setName("jLabel6");

        jLabel7.setText("jLabel7.text");
        jLabel7.setName("jLabel7");

        jLabel8.setText("jLabel8.text");
        jLabel8.setName("jLabel8");

        jLabel9.setText("jLabel9.text");
        jLabel9.setName("jLabel9");

        jLabel10.setText("jLabel10.text");
        jLabel10.setName("jLabel10");

        jLabel11.setText("jLabel11.text");
        jLabel11.setName("jLabel11");

        jLabel12.setText("jLabel12.text");
        jLabel12.setName("jLabel12");

        jLabel13.setText("jLabel13.text");
        jLabel13.setName("jLabel13");

        jLabel14.setText("jLabel14.text");
        jLabel14.setName("jLabel14");

        jLabel15.setText("jLabel15.text");
        jLabel15.setName("jLabel15");

        jLabel16.setText("jLabel16.text");
        jLabel16.setName("jLabel16");

        jLabel17.setText("jLabel17.text");
        jLabel17.setName("jLabel17");

        jLabel18.setText("jLabel18.text");
        jLabel18.setName("jLabel18");

        jLabel19.setText("jLabel19.text");
        jLabel19.setName("jLabel19");

        jLabel20.setText("jLabel20.text"); 
        jLabel20.setName("jLabel20"); 

        jLabel21.setText("jLabel21.text");
        jLabel21.setName("jLabel21");

        jLabel22.setText("jLabel22.text");
        jLabel22.setName("jLabel22");

        jLabel23.setText("jLabel23.text");
        jLabel23.setName("jLabel23");

        jLabel24.setText("jLabel24.text");
        jLabel24.setName("jLabel24");

        jLabel25.setText("jLabel25.text");
        jLabel25.setName("jLabel25");

        jLabel26.setText("jLabel26.text");
        jLabel26.setName("jLabel26");

        jLabel27.setText("jLabel27.text");
        jLabel27.setName("jLabel27");

        jLabel28.setText("jLabel28.text");
        jLabel28.setName("jLabel28");

        jLabel29.setText("jLabel29.text");
        jLabel29.setName("jLabel29");

        jLabel30.setText("jLabel30.text");
        jLabel30.setName("jLabel30");

        jLabel31.setText("jLabel31.text");
        jLabel31.setName("jLabel31");

        jLabel32.setText("jLabel32.text");
        jLabel32.setName("jLabel32");

        jLabel33.setText("jLabel33.text");
        jLabel33.setName("jLabel33");

        jLabel34.setText("jLabel34.text");
        jLabel34.setName("jLabel34");

        jComboBox4.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox4.setName("jComboBox4");

        jLabel35.setText("jLabel35.text");
        jLabel35.setName("jLabel35");

        jLabel36.setText("jLabel36.text");
        jLabel36.setName("jLabel36");

        jLabel37.setText("jLabel37.text");
        jLabel37.setName("jLabel37");

        jLabel38.setText("jLabel38.text");
        jLabel38.setName("jLabel38");

        jLabel39.setText("jLabel39.text");
        jLabel39.setName("jLabel39");

        jLabel40.setText("jLabel40.text");
        jLabel40.setName("jLabel40");

        jLabel41.setText("jLabel41.text");
        jLabel41.setName("jLabel41");

        jLabel42.setText("jLabel42.text");
        jLabel42.setName("jLabel42");

        jLabel43.setText("jLabel43.text");
        jLabel43.setName("jLabel43");

        jLabel44.setText("jLabel44.text");
        jLabel44.setName("jLabel44");

        GroupLayout mainPanelLayout = new GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                        .addGap(41, 41, 41)
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel5)
                                            .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel9)
                                                .addComponent(jLabel7)
                                                .addComponent(jLabel8)
                                                .addComponent(jLabel10, GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel11, GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel12, GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel13, GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel6)))
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                            .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel16)
                                                    .addComponent(jLabel17)
                                                    .addComponent(jLabel18)
                                                    .addComponent(jLabel19)
                                                    .addComponent(jLabel20)
                                                    .addComponent(jLabel21)
                                                    .addComponent(jLabel22)
                                                    .addComponent(jLabel15))
                                                .addGap(72, 72, 72))
                                            .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                                .addComponent(jLabel14)
                                                .addGap(61, 61, 61))))
                                    .addGroup(GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                        .addGap(95, 95, 95)
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jTextField2, GroupLayout.Alignment.TRAILING)
                                            .addComponent(jTextField1, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                            .addComponent(jComboBox4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jButton1))
                                        .addGap(38, 38, 38))))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(33, 33, 33)
                                .addComponent(jLabel4)))
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addGroup(mainPanelLayout.createSequentialGroup()
                                        .addGap(48, 48, 48)
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                            .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel24)
                                                .addComponent(jLabel25)
                                                .addComponent(jLabel26)
                                                .addComponent(jLabel27)
                                                .addComponent(jLabel28)
                                                .addComponent(jLabel29)
                                                .addComponent(jLabel30)
                                                .addComponent(jLabel31))
                                            .addComponent(jLabel44))
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                            .addGroup(mainPanelLayout.createSequentialGroup()
                                                .addGap(236, 236, 236)
                                                .addComponent(jLabel23))
                                            .addGroup(mainPanelLayout.createSequentialGroup()
                                                .addGap(77, 77, 77)
                                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                    .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel33)
                                                        .addComponent(jLabel35)
                                                        .addComponent(jLabel36)
                                                        .addComponent(jLabel37)
                                                        .addComponent(jLabel38)
                                                        .addComponent(jLabel39)
                                                        .addComponent(jLabel40)
                                                        .addComponent(jLabel41))
                                                    .addComponent(jLabel32)))))
                                    .addComponent(jLabel34)))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(47, 47, 47)
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2))
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBox3, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jComboBox1, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jComboBox2, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 155, GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(246, 246, 246)
                        .addComponent(jLabel42))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(202, 202, 202)
                        .addComponent(jLabel43)))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jLabel4)
                        .addGap(66, 66, 66)
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(54, 54, 54)
                                .addComponent(jLabel23))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jComboBox4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jComboBox1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jComboBox2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jComboBox3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
                .addGap(4, 4, 4)
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jLabel5)
                    .addComponent(jLabel44)
                    .addComponent(jLabel32))
                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addGroup(mainPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel15)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel16)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel17)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel18)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel19)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel20)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel21)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel22))
                                    .addGroup(mainPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel6)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel7)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel8)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel9)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel10)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel11)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel12)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel13)))
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel34))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(jLabel24)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel25)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel26)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel27)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel28)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel29, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel30)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel31)))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel42))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel33)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel35)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel36)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel37)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel38)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel39)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel40)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel41)))
                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel43, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(26, Short.MAX_VALUE))
        );
        mainPanel.setVisible(true);
    }
}

Can anyone help me? Currently I'm just trying to get the gui to show. I'll worry about functionality later. That's a lot easier. I used the NetBeans Wysiwyg destkop application builder to build the layouts for the GUI. Here is what it looked like in there.
Image I'm just trying to convert it over to an application.
Last edited by Martyj on Sat May 09, 2009 11:03 pm, edited 1 time in total.
wearymemory
Chaos Rift Junior
Chaos Rift Junior
Posts: 209
Joined: Thu Feb 12, 2009 8:46 pm

Re: Java GUI Problems.

Post by wearymemory »

You can't just call setVisible on a JPanel and expect it to show. You needed to add your mainPanel to your frame, and then call setVisible on that (which I have done for you at the bottom of your initComponents method).

Code: Select all

package test2;


/**
*
* @author MartyJ
*/
import javax.swing.*;
public class Main {
   
    public JFrame frame;
    public JTextField userName;
    public JTextField xp;
    public JButton search;
    public JComboBox combo;
    public JComboBox page;
    public JComboBox page2;
    private JComboBox jComboBox4;
    private JLabel jLabel1;
    private JLabel jLabel10;
    private JLabel jLabel11;
    private JLabel jLabel12;
    private JLabel jLabel13;
    private JLabel jLabel14;
    private JLabel jLabel15;
    private JLabel jLabel16;
    private JLabel jLabel17;
    private JLabel jLabel18;
    private JLabel jLabel19;
    private JLabel jLabel2;
    private JLabel jLabel20;
    private JLabel jLabel21;
    private JLabel jLabel22;
    private JLabel jLabel23;
    private JLabel jLabel24;
    private JLabel jLabel25;
    private JLabel jLabel26;
    private JLabel jLabel27;
    private JLabel jLabel28;
    private JLabel jLabel29;
    private JLabel jLabel3;
    private JLabel jLabel30;
    private JLabel jLabel31;
    private JLabel jLabel32;
    private JLabel jLabel33;
    private JLabel jLabel34;
    private JLabel jLabel35;
    private JLabel jLabel36;
    private JLabel jLabel37;
    private JLabel jLabel38;
    private JLabel jLabel39;
    private JLabel jLabel4;
    private JLabel jLabel40;
    private JLabel jLabel41;
    private JLabel jLabel42;
    private JLabel jLabel43;
    private JLabel jLabel44;
    private JLabel jLabel5;
    private JLabel jLabel6;
    private JLabel jLabel7;
    private JLabel jLabel8;
    private JLabel jLabel9;
    private JPanel mainPanel;
    private JButton jButton1;
    private JComboBox jComboBox1;
    private JComboBox jComboBox2;
    private JComboBox jComboBox3;
    private JTextField jTextField1;
    private JTextField jTextField2;
   
    public Main() {
        initComponents();
    }
     
    public static void main(String[] args){
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main();
            }
        });   
    }
    private void initComponents() {
        mainPanel = new JPanel();
        jButton1 = new JButton();
        jComboBox1 = new JComboBox();
        jComboBox2 = new JComboBox();
        jComboBox3 = new JComboBox();
        jTextField1 = new JTextField();
        jTextField2 = new JTextField();
        jLabel1 = new JLabel();
        jLabel2 = new JLabel();
        jLabel3 = new JLabel();
        jLabel4 = new JLabel();
        jLabel5 = new JLabel();
        jLabel6 = new JLabel();
        jLabel7 = new JLabel();
        jLabel8 = new JLabel();
        jLabel9 = new JLabel();
        jLabel10 = new JLabel();
        jLabel11 = new JLabel();
        jLabel12 = new JLabel();
        jLabel13 = new JLabel();
        jLabel14 = new JLabel();
        jLabel15 = new JLabel();
        jLabel16 = new JLabel();
        jLabel17 = new JLabel();
        jLabel18 = new JLabel();
        jLabel19 = new JLabel();
        jLabel20 = new JLabel();
        jLabel21 = new JLabel();
        jLabel22 = new JLabel();
        jLabel23 = new JLabel();
        jLabel24 = new JLabel();
        jLabel25 = new JLabel();
        jLabel26 = new JLabel();
        jLabel27 = new JLabel();
        jLabel28 = new JLabel();
        jLabel29 = new JLabel();
        jLabel30 = new JLabel();
        jLabel31 = new JLabel();
        jLabel32 = new JLabel();
        jLabel33 = new JLabel();
        jLabel34 = new JLabel();
        jComboBox4 = new JComboBox();
        jLabel35 = new JLabel();
        jLabel36 = new JLabel();
        jLabel37 = new JLabel();
        jLabel38 = new JLabel();
        jLabel39 = new JLabel();
        jLabel40 = new JLabel();
        jLabel41 = new JLabel();
        jLabel42 = new JLabel();
        jLabel43 = new JLabel();
        jLabel44 = new JLabel();

        mainPanel.setMaximumSize(new java.awt.Dimension(500, 500));
        mainPanel.setName("mainPanel");
       
        jButton1.setText("jButton1.text");
        jButton1.setName("jButton1");

        jComboBox1.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.setName("jComboBox1");

        jComboBox2.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox2.setName("jComboBox2");

        jComboBox3.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox3.setName("jComboBox3");

        jTextField1.setText("jTextField1.text");
        jTextField1.setName("jTextField1");

        jTextField2.setText("jTextField2.text");
        jTextField2.setName("jTextField2");

        jLabel1.setText("jLabel1.text");
        jLabel1.setName("jLabel1");

        jLabel2.setText("jLabel2.text");
        jLabel2.setName("jLabel2");

        jLabel3.setText("jLabel3.text");
        jLabel3.setName("jLabel3");

        jLabel4.setText("jLabel4.text");
        jLabel4.setName("jLabel4");

        jLabel5.setText("jLabel5.text");
        jLabel5.setName("jLabel5");

        jLabel6.setText("jLabel6.text");
        jLabel6.setName("jLabel6");

        jLabel7.setText("jLabel7.text");
        jLabel7.setName("jLabel7");

        jLabel8.setText("jLabel8.text");
        jLabel8.setName("jLabel8");

        jLabel9.setText("jLabel9.text");
        jLabel9.setName("jLabel9");

        jLabel10.setText("jLabel10.text");
        jLabel10.setName("jLabel10");

        jLabel11.setText("jLabel11.text");
        jLabel11.setName("jLabel11");

        jLabel12.setText("jLabel12.text");
        jLabel12.setName("jLabel12");

        jLabel13.setText("jLabel13.text");
        jLabel13.setName("jLabel13");

        jLabel14.setText("jLabel14.text");
        jLabel14.setName("jLabel14");

        jLabel15.setText("jLabel15.text");
        jLabel15.setName("jLabel15");

        jLabel16.setText("jLabel16.text");
        jLabel16.setName("jLabel16");

        jLabel17.setText("jLabel17.text");
        jLabel17.setName("jLabel17");

        jLabel18.setText("jLabel18.text");
        jLabel18.setName("jLabel18");

        jLabel19.setText("jLabel19.text");
        jLabel19.setName("jLabel19");

        jLabel20.setText("jLabel20.text");
        jLabel20.setName("jLabel20");

        jLabel21.setText("jLabel21.text");
        jLabel21.setName("jLabel21");

        jLabel22.setText("jLabel22.text");
        jLabel22.setName("jLabel22");

        jLabel23.setText("jLabel23.text");
        jLabel23.setName("jLabel23");

        jLabel24.setText("jLabel24.text");
        jLabel24.setName("jLabel24");

        jLabel25.setText("jLabel25.text");
        jLabel25.setName("jLabel25");

        jLabel26.setText("jLabel26.text");
        jLabel26.setName("jLabel26");

        jLabel27.setText("jLabel27.text");
        jLabel27.setName("jLabel27");

        jLabel28.setText("jLabel28.text");
        jLabel28.setName("jLabel28");

        jLabel29.setText("jLabel29.text");
        jLabel29.setName("jLabel29");

        jLabel30.setText("jLabel30.text");
        jLabel30.setName("jLabel30");

        jLabel31.setText("jLabel31.text");
        jLabel31.setName("jLabel31");

        jLabel32.setText("jLabel32.text");
        jLabel32.setName("jLabel32");

        jLabel33.setText("jLabel33.text");
        jLabel33.setName("jLabel33");

        jLabel34.setText("jLabel34.text");
        jLabel34.setName("jLabel34");

        jComboBox4.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox4.setName("jComboBox4");

        jLabel35.setText("jLabel35.text");
        jLabel35.setName("jLabel35");

        jLabel36.setText("jLabel36.text");
        jLabel36.setName("jLabel36");

        jLabel37.setText("jLabel37.text");
        jLabel37.setName("jLabel37");

        jLabel38.setText("jLabel38.text");
        jLabel38.setName("jLabel38");

        jLabel39.setText("jLabel39.text");
        jLabel39.setName("jLabel39");

        jLabel40.setText("jLabel40.text");
        jLabel40.setName("jLabel40");

        jLabel41.setText("jLabel41.text");
        jLabel41.setName("jLabel41");

        jLabel42.setText("jLabel42.text");
        jLabel42.setName("jLabel42");

        jLabel43.setText("jLabel43.text");
        jLabel43.setName("jLabel43");

        jLabel44.setText("jLabel44.text");
        jLabel44.setName("jLabel44");

        GroupLayout mainPanelLayout = new GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                        .addGap(41, 41, 41)
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel5)
                                            .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel9)
                                                .addComponent(jLabel7)
                                                .addComponent(jLabel8)
                                                .addComponent(jLabel10, GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel11, GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel12, GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel13, GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel6)))
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                            .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel16)
                                                    .addComponent(jLabel17)
                                                    .addComponent(jLabel18)
                                                    .addComponent(jLabel19)
                                                    .addComponent(jLabel20)
                                                    .addComponent(jLabel21)
                                                    .addComponent(jLabel22)
                                                    .addComponent(jLabel15))
                                                .addGap(72, 72, 72))
                                            .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                                .addComponent(jLabel14)
                                                .addGap(61, 61, 61))))
                                    .addGroup(GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                        .addGap(95, 95, 95)
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jTextField2, GroupLayout.Alignment.TRAILING)
                                            .addComponent(jTextField1, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                            .addComponent(jComboBox4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jButton1))
                                        .addGap(38, 38, 38))))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(33, 33, 33)
                                .addComponent(jLabel4)))
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addGroup(mainPanelLayout.createSequentialGroup()
                                        .addGap(48, 48, 48)
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                            .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel24)
                                                .addComponent(jLabel25)
                                                .addComponent(jLabel26)
                                                .addComponent(jLabel27)
                                                .addComponent(jLabel28)
                                                .addComponent(jLabel29)
                                                .addComponent(jLabel30)
                                                .addComponent(jLabel31))
                                            .addComponent(jLabel44))
                                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                            .addGroup(mainPanelLayout.createSequentialGroup()
                                                .addGap(236, 236, 236)
                                                .addComponent(jLabel23))
                                            .addGroup(mainPanelLayout.createSequentialGroup()
                                                .addGap(77, 77, 77)
                                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                    .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel33)
                                                        .addComponent(jLabel35)
                                                        .addComponent(jLabel36)
                                                        .addComponent(jLabel37)
                                                        .addComponent(jLabel38)
                                                        .addComponent(jLabel39)
                                                        .addComponent(jLabel40)
                                                        .addComponent(jLabel41))
                                                    .addComponent(jLabel32)))))
                                    .addComponent(jLabel34)))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(47, 47, 47)
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2))
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBox3, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jComboBox1, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jComboBox2, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 155, GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(246, 246, 246)
                        .addComponent(jLabel42))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(202, 202, 202)
                        .addComponent(jLabel43)))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jLabel4)
                        .addGap(66, 66, 66)
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(54, 54, 54)
                                .addComponent(jLabel23))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jComboBox4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jComboBox1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jComboBox2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jComboBox3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
                .addGap(4, 4, 4)
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jLabel5)
                    .addComponent(jLabel44)
                    .addComponent(jLabel32))
                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addGroup(mainPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel15)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel16)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel17)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel18)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel19)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel20)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel21)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel22))
                                    .addGroup(mainPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel6)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel7)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel8)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel9)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel10)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel11)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel12)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel13)))
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel34))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(jLabel24)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel25)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel26)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel27)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel28)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel29, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel30)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel31)))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel42))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel33)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel35)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel36)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel37)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel38)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel39)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel40)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel41)))
                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel43, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(26, Short.MAX_VALUE))
        );
        
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(mainPanel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
Martyj
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Thu Apr 23, 2009 11:23 am
Location: Ogden Utah
Contact:

Re: Java GUI Problems.

Post by Martyj »

Ok I see. You have to add the panel to the frame then set the frame as visible. Btw what does the pack() method do?

Edit. nvm I'll just look in the documentation or just google it.

Edit.

For anyone that sees this and wonders what the pack method does here is what is written from sun.
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated.
Post Reply