• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A BorderLayout BUG ??

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I'd posted this question before but nobody tried to compile and run this code and jumped to conclusions.
O.K I'm adding 3 buttons to CENTER of a BorderLayout.
I've set Bounds for 2 buttons.Added them first and then a third button to the center.
Ideally i should get only the 3rd button occupying the whole of the frame.BorderLayout does not honour preferred size of the component in the center.
But presto! I'm getting three buttons .The first two exactly as per bounds set over the third.
Please run this small code and see for yourself.
Kindly enlighten me on this one!
-----------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
class Border extends Frame
{
Border()
{
Button b1 = new Button("Button#1");
Button b2 = new Button("Button#2");
Button b3 = new Button("Button#3");
b1.setBounds(20,20,50,50);
b3.setBounds(20,80,50,50);
addWindowListener(new ExitWindow());
add(b1,BorderLayout.CENTER );// try
add(b3,BorderLayout.CENTER);// different
add(b2,BorderLayout.CENTER);// sequences
}
public static void main(String[] args)
{
Border b = new Border();
b.setSize(200,200);
b.show();
}
class ExitWindow extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic