For my application I have a JDialog
which contains a JPanel
with some basic JTextFields
and JButtons
. The idea is to have a button which expands the JDialog
to reveal a second JPanel
which contains some "advance" settings.
I have achieved this with calling setPreferredSize()
and pack()
, but this isn't very elegant. An "elegant" solution would be to set the second Panel to be somehow null and therefore to get ignored by pack() when the toggle state is in "retracted".
Sorry that I can't provide you with code (that thing is about 700 lies) but all it is like I said basically two JPanels in a JDialog.
Here some pics:
Question: is there a trick to get this expanding thing going without having to set fixed dimensions for the expanded/normal state.
There are probably a few ways you could do this, you could, for example, simply add and remove the bottom panel as needed. If I can, I'd like to avoid this, as it can make managing the layout more difficult.
Another solution is simply to make the component visible/invisible, but you need to find a layout manager which will actually treat a invisible component like it's not there (
0x0
) - and yes, I had issues with a couple while putting a test together...It should be noted that the call to
revalidate
is probably irrelevant as you're packing the window anywayUpdated with layout example