SwiXML - BorderLayout and JInternalFrame
[email protected] Wed, 2 Mar 2005 13:57:47 -0800
| Newsgroups | gmane.comp.embedded.carlsbad-cubes |
|---|---|
| Message-ID | <BB7491BA8B7C53409CBD58F7F79D8C3B182053@DED01EXVS01.wcbradley.local> |
Hello All,
I'm pretty new to SwiXML so I may just be missing something so please
point me in the right direction if I am. Otherwise there seems to be a
bug when using BorderLayout as the LayoutManager for a JInternalFrame.
An xml example is as follows. This example is straight out of the
sample code provided.
<internalframe Title="Border Layout" Bounds="390,10,150,150"
Layout="BorderLayout" Visible="true" Resizable="true">
<button constraints="BorderLayout.NORTH">1</button>
<button constraints="BorderLayout.EAST">2</button>
<button constraints="BorderLayout.SOUTH">3</button>
<button constraints="BorderLayout.WEST">4</button>
</internalframe>
This snip from layout.xml in the samples provided does not produce a
proper layout. You only get the last button rendered to show up. In
order to get around this and have a properly rendered border layout for
the above example you need to wrap the buttons with a panel like so.
<internalframe Title="Border Layout" Bounds="390,10,150,150"
Visible="true" Resizable="true">
<panel Layout="BorderLayout">
<button constraints="BorderLayout.NORTH">1</button>
<button constraints="BorderLayout.EAST">2</button>
<button constraints="BorderLayout.SOUTH">3</button>
<button constraints="BorderLayout.WEST">4</button>
</panel>
</internalframe>
This example renders correctly. The problem comes from line 454 of the
Parser.java file. The getSwing method tries to grab the Container
Layout via obj.getLayout().
LayoutManager layoutMgr = obj instanceof Container ? ( (Container) obj
).getLayout() : null;
The Java documentation suggests that for JInternalFrame you need to get
the Layout from the JInternalFrames ContentPane. Thus is should read
obj.getContentPane().getLayout(). For some reason the current code
works fine for all layouts but BorderLayout. In my distribution, I
changed this line to the following.
LayoutManager layoutMgr = null;
if(obj instanceof JInternalFrame)
layoutMgr = ( (JInternalFrame) obj
).getContentPane().getLayout();
else if(obj instanceof Container)
layoutMgr = ( (Container) obj ).getLayout();
After making this change the layout.xml file is rendered correctly. I
am not going to use this change for production now as wrapping a <panel>
around my components is not big deal. To get this to work as it seems
to be intended to work the above change is necessary.
Thanks,
Andrew