I have a GUI in which I want absolute positioning within a subpanel. I'm using GridBagLayout elsewhere, including the parent. When I set the layout manager to null on a top level panel, everything works as I'm expecting. But, when trying to do the same on a subpanel, I get a blank panel (no visible controls). I've reduced this down to a code fragment (based on examples from the web) that can demonstrate this both ways by setting an (obviously named) boolean variable. Here's the code fragment:
Thanks Darryl for the reply. I took your suggestion and came up with the following conclusions.
With the child panel implicitly set to absolute positioning (via "null" LayoutManager), components were displayed properly when the parent panel's layout manager was set to BorderLayout (just as you suggested).
I was hoping that the layout manager setting for the child (including the null setting) would apply to that panel (only!) and not have it (the child) alter its behavior based on the parent's setting. Argh! But, the rest of my application is currently based on the GridBagLayout. Specifically, the parent to my child panel (in this particular case) is (also) GridBagLayout. The child does NOT behave correctly when the parent is GBL, but it DOES behave correctly when BorderLayout. Again, argh!
parent = null -> doesn't work
parent = GridBagLayout -> doesn't work
parent = FlowLayout -> doesn't work (but then again, who cares? I've never used FL in any real application)
Parent stays set to GridBagLayout keeping with my existing design. In fact, there are already multiple layers of GridBagLayout at that point (I think there are 2 layers). I've introduced a new *intermediate* panel that is set to BorderLayout that is otherwise useless. Then there is the child (grandchild?) panel set to null (absolute). The child looks only one level up, sees the intermediate BorderLayout, and behaves correctly. The layers above that still behave according to the GridBagLayout that I intended.
Other than the wasted layer of JPanel, I'm back in business. Gotta love it!
I think you're still missing the point. It's the layout manager that computes the preferredSize for a JPanel. Since you are (unfortunately!) using no layout manager -- and don't keep calling it Absolute layout -- you are responsible for computing the preferredSize or housing the panel in a container with a layout that doesn't necessarily display a child component at its preferredSize.
You might like to read Rob Camick's blog post on Drag Layout and take a look at the section of the code that computes the layout size.