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 theJSplitPane
and 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
divider
location, you can store the current location into a variable (like thedividerLocation
variable in the code) and then when calling thesetDividerLocation
pass in that variable.