Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ButtonType.borderLess #276

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public interface FlatClientProperties
* {@link #BUTTON_TYPE_ROUND_RECT},
* {@link #BUTTON_TYPE_TAB},
* {@link #BUTTON_TYPE_HELP} or
* {@link BUTTON_TYPE_TOOLBAR_BUTTON}
* {@link #BUTTON_TYPE_TOOLBAR_BUTTON}
* {@link #BUTTON_TYPE_BORDERLESS}
*/
String BUTTON_TYPE = "JButton.buttonType";

Expand Down Expand Up @@ -89,6 +90,15 @@ public interface FlatClientProperties
*/
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_BORDERLESS = "borderless";

/**
* Specifies selected state of a checkbox.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class FlatButtonBorder
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
if( FlatButtonUI.isContentAreaFilled( c ) &&
!FlatButtonUI.isToolBarButton( c ) &&
( !FlatButtonUI.isBorderlessButton( c ) || FlatUIUtils.isPermanentFocusOwner( c ) ) &&
!FlatButtonUI.isHelpButton( c ) &&
!FlatToggleButtonUI.isTabButton( c ) )
super.paintBorder( c, g, x, y, width, height );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ static boolean isToolBarButton( Component c ) {
(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_BORDERLESS );
}

@Override
public void update( Graphics g, JComponent c ) {
// fill background if opaque to avoid garbage if user sets opaque to true
Expand Down Expand Up @@ -332,7 +337,7 @@ protected void paintBackground( Graphics g, JComponent c ) {

// paint shadow
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() )
{
g2.setColor( shadowColor );
Expand Down Expand Up @@ -391,7 +396,7 @@ protected Color getBackground( JComponent c ) {
if( ((AbstractButton)c).isSelected() ) {
// in toolbar use same colors for disabled and enabled because
// we assume that toolbar icon is shown disabled
boolean toolBarButton = isToolBarButton( c );
boolean toolBarButton = isToolBarButton( c ) || isBorderlessButton( c );
return buttonStateColor( c,
toolBarButton ? toolbarSelectedBackground : selectedBackground,
toolBarButton ? toolbarSelectedBackground : disabledSelectedBackground,
Expand All @@ -403,7 +408,7 @@ protected Color getBackground( JComponent c ) {
return disabledBackground;

// toolbar button
if( isToolBarButton( c ) ) {
if( isToolBarButton( c ) || isBorderlessButton( c ) ) {
ButtonModel model = ((AbstractButton)c).getModel();
if( model.isPressed() )
return toolbarPressedBackground;
Expand Down Expand Up @@ -465,7 +470,7 @@ protected Color getForeground( JComponent c ) {
if( !c.isEnabled() )
return disabledText;

if( ((AbstractButton)c).isSelected() && !isToolBarButton( c ) )
if( ((AbstractButton)c).isSelected() && !( isToolBarButton( c ) || isBorderlessButton( c ) ) )
return selectedForeground;

// use component foreground if explicitly set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FlatButton
implements FlatComponentExtension
{
// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ private void initComponents() {
JButton button16 = new JButton();
JButton button24 = new JButton();
JButton button20 = new JButton();
JButton button25 = new JButton();
JLabel toggleButtonLabel = new JLabel();
JToggleButton toggleButton1 = new JToggleButton();
FlatToggleButton toggleButton9 = new FlatToggleButton();
Expand All @@ -268,6 +269,7 @@ private void initComponents() {
JToggleButton toggleButton14 = new JToggleButton();
JToggleButton toggleButton21 = new JToggleButton();
JToggleButton toggleButton18 = new JToggleButton();
JToggleButton toggleButton22 = new JToggleButton();
JLabel checkBoxLabel = new JLabel();
JCheckBox checkBox1 = new JCheckBox();
JCheckBox checkBox2 = new JCheckBox();
Expand Down Expand Up @@ -578,6 +580,11 @@ private void initComponents() {
button20.setBorder(BorderFactory.createEmptyBorder());
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.setText("JToggleButton:");
add(toggleButtonLabel, "cell 0 2");
Expand Down Expand Up @@ -655,6 +662,12 @@ private void initComponents() {
toggleButton18.setBorder(BorderFactory.createEmptyBorder());
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.setText("JCheckBox");
add(checkBoxLabel, "cell 0 3");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"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" ) {
name: "toggleButtonLabel"
"text": "JToggleButton:"
Expand Down Expand Up @@ -263,6 +270,14 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"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" ) {
name: "checkBoxLabel"
"text": "JCheckBox"
Expand Down