This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A BorderLayout BUG ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A BorderLayout BUG ??" Watch "A BorderLayout BUG ??" New topic

A BorderLayout BUG ??

Pravin Panicker
Ranch Hand

Joined: Oct 05, 2000
Posts: 62
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
Button b1 = new Button("Button#1");
Button b2 = new Button("Button#2");
Button b3 = new Button("Button#3");
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();
class ExitWindow extends WindowAdapter
public void windowClosing(WindowEvent e)

Pravin R Panicker<br />SCJP,SCWCD
I agree. Here's the link:
subject: A BorderLayout BUG ??
It's not a secret anymore!