JDK-6349028 : Undefined behavior of BorderLayout when component changes constraints
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-11-11
  • Updated: 2011-04-29
Related Reports
Relates :  
Relates :  
Description
This bug came from the 4950972 bug.

The problem is that this:

  container.add(component, BorderLayout.NORTH);

is not quite the same as:

  container.add(component);
  container.getLayout().addLayoutComponent(BorderLayout.NORTH,component);

The latter is what the XMLEncoder creates for the former.
The latter is equivalent to:

  container.add(BorderLayout.CENTER,component);
  container.getLayout().addLayoutComponent(BorderLayout.NORTH,component);

The problem is that the same component is both the CENTER and the NORTH component in the BorderLayout! BorderLayout assigns bounds to the NORTH first and then to the CENTER; our poor component gets its bounds set twice and lands in the center, with space taken in the east for a phantom version.

Comments
EVALUATION As there is nothing in BorderLayout.addLayoutComponent() and in LayoutManager2.addLayoutComponent() about that case then we probably should mention it in the spec. Although this method marked as "Most applications do not call this method directly." it's allowed to use it but the result should be the same as before.
11-11-2005