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.

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

Expanding a JSplitPane either to the left or right direction programmatically is actually easy if you know which component to look at. The split pane bar has a left and right arrow right? Those are actually buttons formed different within the BasicSplitPaneUI class.

Using the code below:

will expand the JSplitPane to the right and hide the right pane while showing the left pane in full. If you want to access the button that will hide the left pane instead while making the right pane visible, use the index zero inside the getComponent() method.

As per version 1.6 of the JDK, there is no MetalSplitPaneDivider class in the API although if you set the JSplitPane‘s UI to use the MetalSplitPaneUI class, it will set the divider’s look and feel to metal. You may want to get access to the divider object like the left and right buttons and by using the BasicSplitPaneDivider class, the divider will not have a metal look and feel.

Luckily, while surfing through the web, I came across the work of Steve Wilson, Tom Santos and Ralph Kar who created two classes: MetalBumps and MetalSplitPaneDivider: so you could have access to the divider object and have a metal look and feel.



Related Posts Plugin for WordPress, Blogger...