I have an application which a JFrame as main window. (The content pane has a tabbedPane, which has a JPanel named "sfp").
Sfp contains two labels, two text fields, one button and other JPanel, called "detail", as show in this image.
Detail panel has few elements, as show this image, but the relevant elements are a check box and the scroll pane.
I want that when I toggle the state of check box, toggle the visibility of the scroll pane (by default not visible), and resizing correctly all JPanel and JFrame.
To switch the visibility of scroll pane, I add this code as action of check box:
protected class DebugAction extends AbstractAction {
public DebugAction() {
this.putValue(Action.NAME, "");
this.putValue(Action.SHORT_DESCRIPTION, "Debug Window");
}
@Override
public void actionPerformed(ActionEvent e) {
if (SFDetail.this.scrollPane.isVisible()) {
SFDetail.this.scrollPane.setVisible(false);
} else {
SFDetail.this.scrollPane.setVisible(true);
}
SFDetail.this.revalidate();
SFDetail.this.repaint();
}
}
But I don't know how to change the JPanel's and JFrame sizes to fit correctly to the visible content.