mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-09 16:25:10 +03:00
ToolBar: support focusable buttons in toolbar (issue #346)
fixed focusable state when switching to/from other Laf
This commit is contained in:
@@ -13,6 +13,8 @@ FlatLaf Change Log
|
||||
- Table and PopupFactory: Use `StackWalker` in Java 9+ for better performance.
|
||||
(issue #334)
|
||||
- ToolBar: Paint focus indicator for focused button in toolbar. (issue #346)
|
||||
- ToolBar: Support focusable buttons in toolbar (set UI values
|
||||
`ToolBar.focusableButtons` to `true`). (issue #346)
|
||||
|
||||
#### Fixed bugs
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.awt.event.ContainerEvent;
|
||||
import java.awt.event.ContainerListener;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicToolBarUI;
|
||||
@@ -41,15 +42,47 @@ import javax.swing.plaf.basic.BasicToolBarUI;
|
||||
* @uiDefault ToolBar.floatingForeground Color
|
||||
* @uiDefault ToolBar.isRollover boolean
|
||||
*
|
||||
* <!-- FlatToolBarUI -->
|
||||
*
|
||||
* @uiDefault ToolBar.focusableButtons boolean
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatToolBarUI
|
||||
extends BasicToolBarUI
|
||||
{
|
||||
/** @since 1.4 */
|
||||
protected boolean focusableButtons;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
return new FlatToolBarUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void installUI( JComponent c ) {
|
||||
super.installUI( c );
|
||||
|
||||
// disable focusable state of buttons (when switching from another Laf)
|
||||
if( !focusableButtons )
|
||||
setButtonsFocusable( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninstallUI( JComponent c ) {
|
||||
super.uninstallUI( c );
|
||||
|
||||
// re-enable focusable state of buttons (when switching to another Laf)
|
||||
if( !focusableButtons )
|
||||
setButtonsFocusable( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
|
||||
focusableButtons = UIManager.getBoolean( "ToolBar.focusableButtons" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContainerListener createToolBarContListener() {
|
||||
return new ToolBarContListener() {
|
||||
@@ -57,22 +90,36 @@ public class FlatToolBarUI
|
||||
public void componentAdded( ContainerEvent e ) {
|
||||
super.componentAdded( e );
|
||||
|
||||
if( !focusableButtons ) {
|
||||
Component c = e.getChild();
|
||||
if( c instanceof AbstractButton )
|
||||
c.setFocusable( false );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentRemoved( ContainerEvent e ) {
|
||||
super.componentRemoved( e );
|
||||
|
||||
if( !focusableButtons ) {
|
||||
Component c = e.getChild();
|
||||
if( c instanceof AbstractButton )
|
||||
c.setFocusable( true );
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
protected void setButtonsFocusable( boolean focusable ) {
|
||||
for( Component c : toolBar.getComponents() ) {
|
||||
if( c instanceof AbstractButton )
|
||||
c.setFocusable( focusable );
|
||||
}
|
||||
}
|
||||
|
||||
// disable rollover border
|
||||
@Override protected void setBorderToRollover( Component c ) {}
|
||||
@Override protected void setBorderToNonRollover( Component c ) {}
|
||||
|
||||
@@ -752,6 +752,7 @@ ToolBar.separatorWidth = 7
|
||||
ToolBar.separatorColor = $Separator.foreground
|
||||
|
||||
ToolBar.spacingBorder = $Button.toolbar.spacingInsets
|
||||
ToolBar.focusableButtons = false
|
||||
|
||||
|
||||
#---- ToolTipManager ----
|
||||
|
||||
@@ -1249,6 +1249,7 @@ ToolBar.dockingBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.dockingForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.floatingBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.floatingForeground #888888 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.focusableButtons false
|
||||
ToolBar.font [active] $defaultFont [UI]
|
||||
ToolBar.foreground #bbbbbb javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.gripColor #adadad javax.swing.plaf.ColorUIResource [UI]
|
||||
|
||||
@@ -1254,6 +1254,7 @@ ToolBar.dockingBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.dockingForeground #000000 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.floatingBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.floatingForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.focusableButtons false
|
||||
ToolBar.font [active] $defaultFont [UI]
|
||||
ToolBar.foreground #000000 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.gripColor #afafaf javax.swing.plaf.ColorUIResource [UI]
|
||||
|
||||
@@ -1263,6 +1263,7 @@ ToolBar.dockingBackground #ccffcc javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.dockingForeground #ff0000 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.floatingBackground #ccffcc javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.floatingForeground #000088 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.focusableButtons true
|
||||
ToolBar.font [active] $defaultFont [UI]
|
||||
ToolBar.foreground #ff0000 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.gripColor #afafaf javax.swing.plaf.ColorUIResource [UI]
|
||||
|
||||
@@ -400,6 +400,11 @@ ToggleButton.pressedBackground = #FFC800
|
||||
ToggleButton.toolbar.selectedBackground = #ddd
|
||||
|
||||
|
||||
#---- ToolBar ----
|
||||
|
||||
ToolBar.focusableButtons = true
|
||||
|
||||
|
||||
#---- ToolTip ----
|
||||
|
||||
ToolTip.background = #eef
|
||||
|
||||
@@ -966,6 +966,7 @@ ToolBar.dockingBackground
|
||||
ToolBar.dockingForeground
|
||||
ToolBar.floatingBackground
|
||||
ToolBar.floatingForeground
|
||||
ToolBar.focusableButtons
|
||||
ToolBar.font
|
||||
ToolBar.foreground
|
||||
ToolBar.gripColor
|
||||
|
||||
Reference in New Issue
Block a user