I am programming a GUI witch a JFrame containing a JScrollPane, which has a JPanel (my mainPanel, BoxLayout.Y_Axis) as its viewPortView.
I can add muliple JPanels to the mainPanel with button clicks. Defined by the BoxLayout these panels align top-down.
Attached a picture of my frame with 3 added panels.
Now my need/problem:
These panels heights should be resizable by mouse (drag/drop) similar to the JSplitPane. But JSplitPane does only support 2 components. Otherwise I needed nested once, which is pretty ugly.
Do you know a better solution or is there even an existing one out there to resize JPanels within a main panel?
Or can you help me out with the automatic "fit-to-windowsize" after invoking setpreferredSize(...)?
I tried a lot, but no approach fullfills my requierements. Sorry for bothering you again.
Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
And you say the problem is when you use setPreferredSize(), so in the SSCCE you don't need to include the custom resizing class. You can add 3 panels to the frame. One will use the setPreferredSize() method. The other two won't. If the problem is the setPreferredSize method then two of the panels should resize correctly, while the third won't.
Joined: Aug 28, 2009
Ok, this is my first SSCCE. I hope it helps to describe my problem.
I added three dummy panels - resizable with a DragBar (inner class).
Again the problem:
If I resize the panel with the drag bar, it keeps its current width even if I reduce the frame's width. I would expect an automatic resize of the panel to the main frame's width. It would be great if you can help me out somehow.