diff --git a/CHANGELOG.md b/CHANGELOG.md index e8354494..9b5934f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,9 +13,13 @@ FlatLaf Change Log - Theming improvements: Reworks core themes to make it easier to create new themes (e.g. reduced explicit colors by using color functions). **Note**: There are minor incompatible changes in FlatLaf properties files. (PR #390) -- ToolBar: Toolbars are no longer floatable by default (dots on left side of - toolbar that allows dragging toolbar). Use `UIManager.put( - "ToolBar.floatable", true )` if you want the old behavior. +- ToolBar: + - Toolbars are no longer floatable by default (dots on left side of toolbar + that allows dragging toolbar). Use `UIManager.put( "ToolBar.floatable", true + )` if you want the old behavior. + - Skip components with empty input map (e.g. `JLabel`) when using arrow keys + to navigate in focusable buttons (if UI value `ToolBar.focusableButtons` is + `true`). - Added more color functions to class `ColorFunctions` for easy use in applications: `lighten()`, `darken()`, `saturate()`, `desaturate()`, `spin()`, `tint()`, `shade()` and `luma()`. diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java index c10fafc3..c4a83cff 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java @@ -24,6 +24,7 @@ import java.awt.event.ContainerListener; import java.beans.PropertyChangeListener; import java.util.Map; import javax.swing.AbstractButton; +import javax.swing.InputMap; import javax.swing.JComponent; import javax.swing.UIManager; import javax.swing.border.Border; @@ -194,6 +195,52 @@ public class FlatToolBarUI } } + /** + * Does the same as super.navigateFocusedComp() with the exception that components + * with empty input map (e.g. JLabel) are skipped. + */ + @Override + protected void navigateFocusedComp( int direction ) { + int count = toolBar.getComponentCount(); + + if( focusedCompIndex < 0 || focusedCompIndex >= count ) + return; + + int add; + switch( direction ) { + case EAST: case SOUTH: add = 1; break; + case WEST: case NORTH: add = -1; break; + default: return; + } + + for( int i = focusedCompIndex + add; i != focusedCompIndex; i += add ) { + if( i < 0 ) + i = count - 1; + else if( i >= count ) + i = 0; + + Component c = toolBar.getComponentAtIndex( i ); + + // see Component.canBeFocusOwner() + if( c == null || !c.isEnabled() || !c.isVisible() || !c.isDisplayable() || !c.isFocusable() ) + continue; // skip + + // check whether component has a empty input map to skip components that + // are focusable, but do nothing when focused (e.g. JLabel) + if( c instanceof JComponent ) { + // see LayoutFocusTraversalPolicy.accept() + InputMap inputMap = ((JComponent)c).getInputMap( JComponent.WHEN_FOCUSED ); + while( inputMap != null && inputMap.size() == 0 ) + inputMap = inputMap.getParent(); + if( inputMap == null ) + continue; // skip + } + + c.requestFocus(); + return; + } + } + // disable rollover border @Override protected void setBorderToRollover( Component c ) {} @Override protected void setBorderToNonRollover( Component c ) {}