How To Enable/Disable Buttons Of JSplitPane

I thought that calling setEnabled() on a JSplitPane object will also enable/disable the divider buttons. I found out it does not. Only the divider gets disabled so when you click on the buttons, the JSplitPane will still be resized.

To get a reference on the buttons, you make use of the BasicSplitPaneUI class, cast it and call setEnabled() on them.

Check the code below.

BasicSplitPaneUI ui = (BasicSplitPaneUI) mySplitPane.getUI();
((JButton) ui.getDivider().getComponent(0)).setEnabled(false);
((JButton) ui.getDivider().getComponent(1)).setEnabled(false);

That should let you enable or disable the buttons of the JSplitPane divider.

Donations appreciated. Every little $ helps. Or click Google +1.

Related Posts Plugin for WordPress, Blogger...

Post a Comment