So I have one jFrame object ,which in turn has 3 JPanels attached to it. These JPanels are placed on NORTH,CENTER,SOUTH. I added some buttons and labels to CENTER and SOUTH.
I added in some fieldsets on NORTH and CENTER to give it a nicer look. Now when I try to run the program ,it doesn't show anything. My buttons and labels disappear and my fieldsets are nowhere to be found. What am I doing wrong?
Thank you for you time.
public General() {
super("OmniTool");
initComponents();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(300,100);
setVisible(true);
setResizable(true);
setSize(900, 700);
//radiobuttons ivm dependencies
ButtonGroup dependenciesInfo = new ButtonGroup();
dependenciesInfo.add(rdbYesDependencies);
dependenciesInfo.add(rdbNoDependencies);
//boolean om te controleren of alle textareas al ingevuld zijn
generalInfoComplete = false;
//creating 3 panels and add them on the same frame + giving them their location
JPanel oudeMod = new JPanel();
JPanel nieuweMod = new JPanel();
JPanel generate = new JPanel();
this.add(oudeMod,BorderLayout.NORTH);
this.add(nieuweMod,BorderLayout.CENTER);
this.add(generate,BorderLayout.SOUTH);
oudeMod.setBorder(BorderFactory.createTitledBorder("Use exisiting modfolder"));
nieuweMod.setBorder(BorderFactory.createTitledBorder("Create new modfolder"));
//adding buttons and textfields to proper panels
nieuweMod.add(jLabel2);
nieuweMod.add(jLabel3);
nieuweMod.add(jLabel4);
nieuweMod.add(jLabel5);
nieuweMod.add(jLabel7);
nieuweMod.add(jLabel8);
nieuweMod.add(jLabel9);
nieuweMod.add(jLabel10);
nieuweMod.add(btnBrowseMain);
nieuweMod.add(btnBrowseMods);
nieuweMod.add(btnDependencies);
nieuweMod.add(rdbNoDependencies);
nieuweMod.add(rdbYesDependencies);
nieuweMod.add(txtDependencies);
nieuweMod.add(txtMainDir);
nieuweMod.add(txtModName);
nieuweMod.add(txtModsDir);
generate.add(btnGenerate);
}
EDIT1: These jFrames are on 1 jtabbedPane.
if "this" is the JFrame, this.add(...) won't work. You should add your components to the contentPane of the JFrame.
"So I have one jFrame object ,which in turn has 3 JPanels attached to it. These JPanels are placed on NORTH,CENTER,SOUTH. I added some buttons and labels to CENTER and SOUTH."
Each BorderLayout
position can only hold one component. If you add a JPanel
to the CENTER
then add the JButton
to the CENTER
only the last component added (the JButton
) will appear.
Add whatever components you need to a max 5 JPanel
s and position those JPanel
at the different BorderLayout
positions. Or you can use a different layout. Or you can use a main JPanel
container and just add the JPanel
to the frame. You have many options.
Also do all your JFrame
housekeeping after you add all your components. Put them at the end of your constructor.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(300,100);
setVisible(true);
setResizable(true);
setSize(900, 700);
Don't set size either. Just pack()
. And setVisible()
should be the last thing you do.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
setResizable(true);
setVisible(true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.