Skip to content

Commit bd5512c

Browse files
committed
SplitPane: allow limiting one-touch expanding to a single side (issue #355)
1 parent 9afce83 commit bd5512c

3 files changed

Lines changed: 50 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ FlatLaf Change Log
55

66
#### New features and improvements
77

8+
- SplitPane: Allow limiting one-touch expanding to a single side (set client
9+
property `JSplitPane.expandableSide` to `"left"` or `"right"`). (issue #355)
810
- TabbedPane: Selected tab underline color now changes depending on whether the
911
focus is within the tab content. (issue #398)
1012
- IntelliJ Themes:

flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,40 @@ public interface FlatClientProperties
391391
*/
392392
String SCROLL_PANE_SMOOTH_SCROLLING = "JScrollPane.smoothScrolling";
393393

394+
//---- JSplitPane ---------------------------------------------------------
395+
396+
/**
397+
* Specifies what side of the spilt pane is allowed to expand
398+
* via one-touch expanding arrow buttons.
399+
* Requires that one-touch expanding is enabled with
400+
* {@link javax.swing.JSplitPane#setOneTouchExpandable(boolean)}.
401+
* <p>
402+
* <strong>Component</strong> {@link javax.swing.JSplitPane}<br>
403+
* <strong>Value type</strong> {@link java.lang.String}<br>
404+
* <strong>Allowed Values</strong>
405+
* {@link #SPLIT_PANE_EXPANDABLE_SIDE_LEFT} or
406+
* {@link #SPLIT_PANE_EXPANDABLE_SIDE_RIGHT}
407+
*
408+
* @since 2.2
409+
*/
410+
String SPLIT_PANE_EXPANDABLE_SIDE = "JSplitPane.expandableSide";
411+
412+
/**
413+
* Allow expanding only left/top side of the split pane.
414+
*
415+
* @see #SPLIT_PANE_EXPANDABLE_SIDE
416+
* @since 2.2
417+
*/
418+
String SPLIT_PANE_EXPANDABLE_SIDE_LEFT = "left";
419+
420+
/**
421+
* Allow expanding only right/bottom side of the split pane.
422+
*
423+
* @see #SPLIT_PANE_EXPANDABLE_SIDE
424+
* @since 2.2
425+
*/
426+
String SPLIT_PANE_EXPANDABLE_SIDE_RIGHT = "right";
427+
394428
//---- JTabbedPane --------------------------------------------------------
395429

396430
/**

flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSplitPaneUI.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.swing.plaf.ComponentUI;
3535
import javax.swing.plaf.basic.BasicSplitPaneDivider;
3636
import javax.swing.plaf.basic.BasicSplitPaneUI;
37+
import com.formdev.flatlaf.FlatClientProperties;
3738
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
3839
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
3940
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
@@ -352,7 +353,7 @@ public void layoutContainer( Container c ) {
352353
if( leftButton == null || rightButton == null || !splitPane.isOneTouchExpandable() )
353354
return;
354355

355-
// increase side of buttons, which makes them easier to hit by the user
356+
// increase size of buttons, which makes them easier to hit by the user
356357
// and avoids cut arrows at small divider sizes
357358
int extraSize = UIScale.scale( 4 );
358359
if( orientation == JSplitPane.VERTICAL_SPLIT ) {
@@ -367,10 +368,19 @@ public void layoutContainer( Container c ) {
367368

368369
// hide buttons if not applicable
369370
boolean leftCollapsed = isLeftCollapsed();
370-
if( leftCollapsed )
371+
boolean rightCollapsed = isRightCollapsed();
372+
if( leftCollapsed || rightCollapsed ) {
373+
leftButton.setVisible( !leftCollapsed );
374+
rightButton.setVisible( !rightCollapsed );
375+
} else {
376+
Object expandableSide = splitPane.getClientProperty( FlatClientProperties.SPLIT_PANE_EXPANDABLE_SIDE );
377+
leftButton.setVisible( expandableSide == null || !FlatClientProperties.SPLIT_PANE_EXPANDABLE_SIDE_LEFT.equals( expandableSide ) );
378+
rightButton.setVisible( expandableSide == null || !FlatClientProperties.SPLIT_PANE_EXPANDABLE_SIDE_RIGHT.equals( expandableSide ) );
379+
}
380+
381+
// move right button if left button is hidden
382+
if( !leftButton.isVisible() )
371383
rightButton.setLocation( leftButton.getLocation() );
372-
leftButton.setVisible( !leftCollapsed );
373-
rightButton.setVisible( !isRightCollapsed() );
374384
}
375385
}
376386
}

0 commit comments

Comments
 (0)