According to camickr answer and comments, see how I solved it:
Point A is due to my free layout used in NetBeans. I did not succeed to fix my code so I changed the structure of my elements. It is probably not optimal and does not use all the swing concepts right, but it works the way I want.
I have a JLayeredPane
in the background that uses a GridBagLayout
. This background pane contains one column of JPanel
of height 30 and 260, one for the summary line, the other one for the details.
The expand/collapse function controlled by the JToggleButton
works by hiding the below panel belowPanel.setVisibility(false)
. No need for repack or anything, just that. Here is how the code looks like without changing the button's icon:
private void inverseVisibility(JToggleButton expand, JPanel target) {
if (expand.isSelected()) {
target.setVisible(true);
} else {
target.setVisible(false);
}
}
As I only wanted the elements to resize horizontally, all my panels have Horizontal
as Fill
value and Northwest
as Anchor
. I've set the weightX = 1; weightY = 0
. Finally I added a panel in the bottom with a Southwest
anchor and fill both
along with both weights to 1
(not sure it changes anything but this way I am certain that it will fill all the blank space at the bottom it the window is resized at a bigger size than its content).
Point B has been solved by taking my background panel, that fit in my Frame
, and putting it into a JScrollPane
. The error I had was due to the Netbeans editor that did not properly stick the scroll pane to the side of the frame, due to incoherences in the sizes defined in both the frame and the scroll pane. My advise to you if you are using this tool is to set the fewest values as possible as a lot of values are heavily interconnected by the gui designer.
Get the full code (95,864 bytes)