• Post Reply Bookmark Topic Watch Topic
  • New Topic

BorderLayout help  RSS feed

 
Frank Hale
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the following code the layout the ImageIcon and Button ignore the placement I give them. Why?
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panel = new JPanel();

ImageIcon i = new ImageIcon("purejava.gif");
JLabel label = new JLabel(i);
panel.add(label, BorderLayout.NORTH);

JButton button = new JButton("Hello,World");
panel.add(button, BorderLayout.SOUTH);

tabbedPane.addTab("Test tab", null, panel, "Hello,World");

container.add(tabbedPane);
Thanks,
Frank
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default layout manager for a JPanel (or Panel) is FlowLayout, not BorderLayout. It's annoying that this program doesn't throw an error as soon as you do add(label, BorderLayout.NORTH) with a FlowLayout as manager - but apparantly no one thought of that when designing layout managers. Ah well...
 
Frank Hale
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out all I had to do was set the panels layout like so
panel.setLayout(new BorderLayout());
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!