Reputation: 177
doing some self study for a simple GUI interface for Java. Tried to code a simple interface. Here is the below code:
public void MainPanel() {
JFrame frame = new JFrame();
frame.setTitle("Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTabbedPane mpt = new JTabbedPane();
mpt.addTab("Intro", new IntroPanel());
mpt.addTab("Catalogue", new CataloguePanel());
mpt.addTab("Order", new OrderPanel());
mpt.addTab("Track", new TrackPanel());
JPanel main = new JPanel();
main.setBackground(Color.white);
JLabel label1 = new JLabel("Intro");
main.add(label1);
frame.add(main);
frame.add(mpt);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
The problem I am currently facing is: If I put frame.add(main)
infront of frame.add(mpt)
, only the tabs will appear but the the label intro. If I put frame.add(mpt)
infront of frame.add(main)
. Intro will appear but not the tabs.
Why is this happening? Why are they overlapping each other? I did it the same way as some tutorial but to no avail..
Upvotes: 0
Views: 437
Reputation: 15333
Try giving it some other layout.
eg. frame.setLayout(new FlowLayout());
Info:
According to Java Naming Conventions your method's name should be like public void mainPanel()
Upvotes: 4