ToolBar: fixed focus moving to next button when switching Laf and focusable buttons are enabled via CSS style focusableButtons: true

also avoid unnecessary invokation of `c.setFocusable()`
This commit is contained in:
Karl Tauber
2021-10-05 15:34:23 +02:00
parent 16ea809bb3
commit 1e93deab2a

View File

@@ -83,11 +83,13 @@ public class FlatToolBarUI
public void installUI( JComponent c ) {
super.installUI( c );
installStyle();
// disable focusable state of buttons (when switching from another Laf)
// do this after applying style to avoid disabling (here) and re-enabling
// (in applyStyle()), which would transfer focus to next button
if( !focusableButtons )
setButtonsFocusable( false );
installStyle();
}
@Override
@@ -132,22 +134,16 @@ public class FlatToolBarUI
public void componentAdded( ContainerEvent e ) {
super.componentAdded( e );
if( !focusableButtons ) {
Component c = e.getChild();
if( c instanceof AbstractButton )
c.setFocusable( false );
}
if( !focusableButtons )
setButtonFocusable( e.getChild(), false );
}
@Override
public void componentRemoved( ContainerEvent e ) {
super.componentRemoved( e );
if( !focusableButtons ) {
Component c = e.getChild();
if( c instanceof AbstractButton )
c.setFocusable( true );
}
if( !focusableButtons )
setButtonFocusable( e.getChild(), true );
}
};
}
@@ -189,10 +185,13 @@ public class FlatToolBarUI
/** @since 1.4 */
protected void setButtonsFocusable( boolean focusable ) {
for( Component c : toolBar.getComponents() ) {
if( c instanceof AbstractButton )
c.setFocusable( focusable );
}
for( Component c : toolBar.getComponents() )
setButtonFocusable( c, focusable );
}
private void setButtonFocusable( Component c, boolean focusable ) {
if( c instanceof AbstractButton && focusable != c.isFocusable() )
c.setFocusable( focusable );
}
/**