mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 15:27:16 -06:00
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:
@@ -83,11 +83,13 @@ public class FlatToolBarUI
|
|||||||
public void installUI( JComponent c ) {
|
public void installUI( JComponent c ) {
|
||||||
super.installUI( c );
|
super.installUI( c );
|
||||||
|
|
||||||
|
installStyle();
|
||||||
|
|
||||||
// disable focusable state of buttons (when switching from another Laf)
|
// 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 )
|
if( !focusableButtons )
|
||||||
setButtonsFocusable( false );
|
setButtonsFocusable( false );
|
||||||
|
|
||||||
installStyle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -132,22 +134,16 @@ public class FlatToolBarUI
|
|||||||
public void componentAdded( ContainerEvent e ) {
|
public void componentAdded( ContainerEvent e ) {
|
||||||
super.componentAdded( e );
|
super.componentAdded( e );
|
||||||
|
|
||||||
if( !focusableButtons ) {
|
if( !focusableButtons )
|
||||||
Component c = e.getChild();
|
setButtonFocusable( e.getChild(), false );
|
||||||
if( c instanceof AbstractButton )
|
|
||||||
c.setFocusable( false );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentRemoved( ContainerEvent e ) {
|
public void componentRemoved( ContainerEvent e ) {
|
||||||
super.componentRemoved( e );
|
super.componentRemoved( e );
|
||||||
|
|
||||||
if( !focusableButtons ) {
|
if( !focusableButtons )
|
||||||
Component c = e.getChild();
|
setButtonFocusable( e.getChild(), true );
|
||||||
if( c instanceof AbstractButton )
|
|
||||||
c.setFocusable( true );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -189,10 +185,13 @@ public class FlatToolBarUI
|
|||||||
|
|
||||||
/** @since 1.4 */
|
/** @since 1.4 */
|
||||||
protected void setButtonsFocusable( boolean focusable ) {
|
protected void setButtonsFocusable( boolean focusable ) {
|
||||||
for( Component c : toolBar.getComponents() ) {
|
for( Component c : toolBar.getComponents() )
|
||||||
if( c instanceof AbstractButton )
|
setButtonFocusable( c, focusable );
|
||||||
c.setFocusable( focusable );
|
}
|
||||||
}
|
|
||||||
|
private void setButtonFocusable( Component c, boolean focusable ) {
|
||||||
|
if( c instanceof AbstractButton && focusable != c.isFocusable() )
|
||||||
|
c.setFocusable( focusable );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user