I have a JSplitPane with two sections. I want to hide the right section when I click a button, and bring it back when I click on that same button again.
Here is what I have so far:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if (PrincipalSplitPane.getDividerSize() == 1.0)
PrincipalSplitPane.setDividerLocation(0.0);
else
PrincipalSplitPane.setDividerLocation(1.0);
}
You can use the
getRightComponent()method of theJSplitPaneand then call thesetVisible(false)to hide it.To show it again, call the
setVisible(true)and set the divider location using thesetDividerLocation(...)method.An Example
If you need to save the previous
dividerlocation, you can store the current location into a variable (like thedividerLocationvariable in the code) and then when calling thesetDividerLocationpass in that variable.