wood burning stoves*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A BorderLayout BUG ??" Watch "A BorderLayout BUG ??" New topic
Author

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
{
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);
}
}
}

Pravin R Panicker<br />SCJP,SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A BorderLayout BUG ??
 
Similar Threads
Problem in State Design Pattern
Problem with repaint()
Strange BorderLayout !!
Writing to file problems
Problem regarding Border Layout