mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 22:40:53 +03:00
Added ButtonType.borderLess for buttons that look like toolbar buttons but have a focus indicator.
This behavior can be achieved with JideButton, but it would be preferable to use FlatButton instead.
This commit is contained in:
@@ -40,7 +40,8 @@ public interface FlatClientProperties
|
|||||||
* {@link #BUTTON_TYPE_ROUND_RECT},
|
* {@link #BUTTON_TYPE_ROUND_RECT},
|
||||||
* {@link #BUTTON_TYPE_TAB},
|
* {@link #BUTTON_TYPE_TAB},
|
||||||
* {@link #BUTTON_TYPE_HELP} or
|
* {@link #BUTTON_TYPE_HELP} or
|
||||||
* {@link BUTTON_TYPE_TOOLBAR_BUTTON}
|
* {@link #BUTTON_TYPE_TOOLBAR_BUTTON}
|
||||||
|
* {@link #BUTTON_TYPE_BORDER_LESS}
|
||||||
*/
|
*/
|
||||||
String BUTTON_TYPE = "JButton.buttonType";
|
String BUTTON_TYPE = "JButton.buttonType";
|
||||||
|
|
||||||
@@ -89,6 +90,15 @@ public interface FlatClientProperties
|
|||||||
*/
|
*/
|
||||||
String BUTTON_TYPE_TOOLBAR_BUTTON = "toolBarButton";
|
String BUTTON_TYPE_TOOLBAR_BUTTON = "toolBarButton";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paint the button without a border in the unfocused state.
|
||||||
|
* <p>
|
||||||
|
* <strong>Components</strong> {@link javax.swing.JButton} and {@link javax.swing.JToggleButton}
|
||||||
|
*
|
||||||
|
* @see #BUTTON_TYPE
|
||||||
|
*/
|
||||||
|
String BUTTON_TYPE_BORDER_LESS = "borderLess";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies selected state of a checkbox.
|
* Specifies selected state of a checkbox.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ public class FlatButtonBorder
|
|||||||
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
|
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
|
||||||
if( FlatButtonUI.isContentAreaFilled( c ) &&
|
if( FlatButtonUI.isContentAreaFilled( c ) &&
|
||||||
!FlatButtonUI.isToolBarButton( c ) &&
|
!FlatButtonUI.isToolBarButton( c ) &&
|
||||||
|
( !FlatButtonUI.isBorderLessButton( c ) || FlatUIUtils.isPermanentFocusOwner( c ) ) &&
|
||||||
!FlatButtonUI.isHelpButton( c ) &&
|
!FlatButtonUI.isHelpButton( c ) &&
|
||||||
!FlatToggleButtonUI.isTabButton( c ) )
|
!FlatToggleButtonUI.isTabButton( c ) )
|
||||||
super.paintBorder( c, g, x, y, width, height );
|
super.paintBorder( c, g, x, y, width, height );
|
||||||
|
|||||||
@@ -285,6 +285,10 @@ public class FlatButtonUI
|
|||||||
(c instanceof AbstractButton && clientPropertyEquals( (AbstractButton) c, BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON ));
|
(c instanceof AbstractButton && clientPropertyEquals( (AbstractButton) c, BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean isBorderLessButton( Component c ) {
|
||||||
|
return c instanceof AbstractButton && clientPropertyEquals( (AbstractButton) c, BUTTON_TYPE, BUTTON_TYPE_BORDER_LESS );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void update( Graphics g, JComponent c ) {
|
||||||
// fill background if opaque to avoid garbage if user sets opaque to true
|
// fill background if opaque to avoid garbage if user sets opaque to true
|
||||||
@@ -332,7 +336,7 @@ public class FlatButtonUI
|
|||||||
|
|
||||||
// paint shadow
|
// paint shadow
|
||||||
Color shadowColor = def ? defaultShadowColor : this.shadowColor;
|
Color shadowColor = def ? defaultShadowColor : this.shadowColor;
|
||||||
if( !isToolBarButton && shadowColor != null && shadowWidth > 0 && focusWidth > 0 &&
|
if( !isToolBarButton && !isBorderLessButton( c ) && shadowColor != null && shadowWidth > 0 && focusWidth > 0 &&
|
||||||
!(isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c )) && c.isEnabled() )
|
!(isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c )) && c.isEnabled() )
|
||||||
{
|
{
|
||||||
g2.setColor( shadowColor );
|
g2.setColor( shadowColor );
|
||||||
@@ -391,7 +395,7 @@ public class FlatButtonUI
|
|||||||
if( ((AbstractButton)c).isSelected() ) {
|
if( ((AbstractButton)c).isSelected() ) {
|
||||||
// in toolbar use same colors for disabled and enabled because
|
// in toolbar use same colors for disabled and enabled because
|
||||||
// we assume that toolbar icon is shown disabled
|
// we assume that toolbar icon is shown disabled
|
||||||
boolean toolBarButton = isToolBarButton( c );
|
boolean toolBarButton = isToolBarButton( c ) || isBorderLessButton( c );
|
||||||
return buttonStateColor( c,
|
return buttonStateColor( c,
|
||||||
toolBarButton ? toolbarSelectedBackground : selectedBackground,
|
toolBarButton ? toolbarSelectedBackground : selectedBackground,
|
||||||
toolBarButton ? toolbarSelectedBackground : disabledSelectedBackground,
|
toolBarButton ? toolbarSelectedBackground : disabledSelectedBackground,
|
||||||
@@ -403,7 +407,7 @@ public class FlatButtonUI
|
|||||||
return disabledBackground;
|
return disabledBackground;
|
||||||
|
|
||||||
// toolbar button
|
// toolbar button
|
||||||
if( isToolBarButton( c ) ) {
|
if( isToolBarButton( c ) || isBorderLessButton( c ) ) {
|
||||||
ButtonModel model = ((AbstractButton)c).getModel();
|
ButtonModel model = ((AbstractButton)c).getModel();
|
||||||
if( model.isPressed() )
|
if( model.isPressed() )
|
||||||
return toolbarPressedBackground;
|
return toolbarPressedBackground;
|
||||||
@@ -465,7 +469,7 @@ public class FlatButtonUI
|
|||||||
if( !c.isEnabled() )
|
if( !c.isEnabled() )
|
||||||
return disabledText;
|
return disabledText;
|
||||||
|
|
||||||
if( ((AbstractButton)c).isSelected() && !isToolBarButton( c ) )
|
if( ((AbstractButton)c).isSelected() && !( isToolBarButton( c ) || isBorderLessButton( c ) ) )
|
||||||
return selectedForeground;
|
return selectedForeground;
|
||||||
|
|
||||||
// use component foreground if explicitly set
|
// use component foreground if explicitly set
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class FlatButton
|
|||||||
implements FlatComponentExtension
|
implements FlatComponentExtension
|
||||||
{
|
{
|
||||||
// NOTE: enum names must be equal to allowed strings
|
// NOTE: enum names must be equal to allowed strings
|
||||||
public enum ButtonType { none, square, roundRect, tab, help, toolBarButton };
|
public enum ButtonType { none, square, roundRect, tab, help, toolBarButton, borderLess }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns type of a button.
|
* Returns type of a button.
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ public class FlatComponentsTest
|
|||||||
JButton button16 = new JButton();
|
JButton button16 = new JButton();
|
||||||
JButton button24 = new JButton();
|
JButton button24 = new JButton();
|
||||||
JButton button20 = new JButton();
|
JButton button20 = new JButton();
|
||||||
|
JButton button25 = new JButton();
|
||||||
JLabel toggleButtonLabel = new JLabel();
|
JLabel toggleButtonLabel = new JLabel();
|
||||||
JToggleButton toggleButton1 = new JToggleButton();
|
JToggleButton toggleButton1 = new JToggleButton();
|
||||||
FlatToggleButton toggleButton9 = new FlatToggleButton();
|
FlatToggleButton toggleButton9 = new FlatToggleButton();
|
||||||
@@ -268,6 +269,7 @@ public class FlatComponentsTest
|
|||||||
JToggleButton toggleButton14 = new JToggleButton();
|
JToggleButton toggleButton14 = new JToggleButton();
|
||||||
JToggleButton toggleButton21 = new JToggleButton();
|
JToggleButton toggleButton21 = new JToggleButton();
|
||||||
JToggleButton toggleButton18 = new JToggleButton();
|
JToggleButton toggleButton18 = new JToggleButton();
|
||||||
|
JToggleButton toggleButton22 = new JToggleButton();
|
||||||
JLabel checkBoxLabel = new JLabel();
|
JLabel checkBoxLabel = new JLabel();
|
||||||
JCheckBox checkBox1 = new JCheckBox();
|
JCheckBox checkBox1 = new JCheckBox();
|
||||||
JCheckBox checkBox2 = new JCheckBox();
|
JCheckBox checkBox2 = new JCheckBox();
|
||||||
@@ -578,6 +580,11 @@ public class FlatComponentsTest
|
|||||||
button20.setBorder(BorderFactory.createEmptyBorder());
|
button20.setBorder(BorderFactory.createEmptyBorder());
|
||||||
add(button20, "cell 5 1 2 1");
|
add(button20, "cell 5 1 2 1");
|
||||||
|
|
||||||
|
//---- button25 ----
|
||||||
|
button25.setIcon(UIManager.getIcon("Tree.closedIcon"));
|
||||||
|
button25.putClientProperty("JButton.buttonType", "borderLess");
|
||||||
|
add(button25, "cell 5 1 2 1");
|
||||||
|
|
||||||
//---- toggleButtonLabel ----
|
//---- toggleButtonLabel ----
|
||||||
toggleButtonLabel.setText("JToggleButton:");
|
toggleButtonLabel.setText("JToggleButton:");
|
||||||
add(toggleButtonLabel, "cell 0 2");
|
add(toggleButtonLabel, "cell 0 2");
|
||||||
@@ -655,6 +662,12 @@ public class FlatComponentsTest
|
|||||||
toggleButton18.setBorder(BorderFactory.createEmptyBorder());
|
toggleButton18.setBorder(BorderFactory.createEmptyBorder());
|
||||||
add(toggleButton18, "cell 5 2 2 1");
|
add(toggleButton18, "cell 5 2 2 1");
|
||||||
|
|
||||||
|
//---- toggleButton22 ----
|
||||||
|
toggleButton22.setIcon(UIManager.getIcon("Tree.closedIcon"));
|
||||||
|
toggleButton22.setSelected(true);
|
||||||
|
toggleButton22.putClientProperty("JButton.buttonType", "borderLess");
|
||||||
|
add(toggleButton22, "cell 5 2 2 1");
|
||||||
|
|
||||||
//---- checkBoxLabel ----
|
//---- checkBoxLabel ----
|
||||||
checkBoxLabel.setText("JCheckBox");
|
checkBoxLabel.setText("JCheckBox");
|
||||||
add(checkBoxLabel, "cell 0 3");
|
add(checkBoxLabel, "cell 0 3");
|
||||||
|
|||||||
@@ -156,6 +156,13 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 5 1 2 1"
|
"value": "cell 5 1 2 1"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
|
name: "button25"
|
||||||
|
"icon": &SwingIcon0 new com.jformdesigner.model.SwingIcon( 2, "Tree.closedIcon" )
|
||||||
|
"$client.JButton.buttonType": "borderLess"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 5 1 2 1"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "toggleButtonLabel"
|
name: "toggleButtonLabel"
|
||||||
"text": "JToggleButton:"
|
"text": "JToggleButton:"
|
||||||
@@ -263,6 +270,14 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 5 2 2 1"
|
"value": "cell 5 2 2 1"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JToggleButton" ) {
|
||||||
|
name: "toggleButton22"
|
||||||
|
"icon": &SwingIcon0 new com.jformdesigner.model.SwingIcon( 2, "Tree.closedIcon" )
|
||||||
|
"selected": true
|
||||||
|
"$client.JButton.buttonType": "borderLess"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 5 2 2 1"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "checkBoxLabel"
|
name: "checkBoxLabel"
|
||||||
"text": "JCheckBox"
|
"text": "JCheckBox"
|
||||||
|
|||||||
Reference in New Issue
Block a user