Menus: changed menu bar and popup menu background colors (made brighter in light themes and darker in dark themes)

made `JMenu`, `JMenuItem`, `JCheckBoxMenuItem` and `JRadioButtonMenuItem` non-opaque
This commit is contained in:
Karl Tauber
2020-01-20 17:55:21 +01:00
parent 409a773e36
commit 7433dc9cf3
5 changed files with 39 additions and 2 deletions

View File

@@ -3,6 +3,12 @@ FlatLaf Change Log
## Unreleased ## Unreleased
- Menus:
- Changed menu bar and popup menu background colors (made brighter in light
themes and darker in dark themes).
- Popup menus now have empty space at the top and bottom.
- Made `JMenu`, `JMenuItem`, `JCheckBoxMenuItem` and `JRadioButtonMenuItem`
non-opaque.
- TextField, FormattedTextField and PasswordField: Select all text when a text - TextField, FormattedTextField and PasswordField: Select all text when a text
field gains focus for the first time and selection was not set explicitly. field gains focus for the first time and selection was not set explicitly.
This can be configured to newer or always select all text on focus gain (see This can be configured to newer or always select all text on focus gain (see

View File

@@ -16,7 +16,12 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import java.awt.Component;
import java.awt.Container;
import java.awt.Insets;
import javax.swing.JScrollPane;
import javax.swing.UIManager; import javax.swing.UIManager;
import com.formdev.flatlaf.util.UIScale;
/** /**
* Border for {@link javax.swing.JPopupMenu}. * Border for {@link javax.swing.JPopupMenu}.
@@ -33,4 +38,18 @@ public class FlatPopupMenuBorder
super( UIManager.getInsets( "PopupMenu.borderInsets" ), super( UIManager.getInsets( "PopupMenu.borderInsets" ),
UIManager.getColor( "PopupMenu.borderColor" ) ); UIManager.getColor( "PopupMenu.borderColor" ) );
} }
@Override
public Insets getBorderInsets( Component c, Insets insets ) {
if( c instanceof Container &&
((Container)c).getComponentCount() > 0 &&
((Container)c).getComponent( 0 ) instanceof JScrollPane )
{
// e.g. for combobox popups
insets.left = insets.top = insets.right = insets.bottom = UIScale.scale( 1 );
return insets;
}
return super.getBorderInsets( c, insets );
}
} }

View File

@@ -28,6 +28,7 @@
@selectionInactiveForeground=@foreground @selectionInactiveForeground=@foreground
@disabledText=#777777 @disabledText=#777777
@textComponentBackground=#45494A @textComponentBackground=#45494A
@menuBackground=darken(@background,5%)
@cellFocusColor=#000000 @cellFocusColor=#000000
@icon=#adadad @icon=#adadad

View File

@@ -121,6 +121,8 @@ CheckBoxMenuItem.border=com.formdev.flatlaf.ui.FlatMarginBorder
CheckBoxMenuItem.checkIcon=com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon CheckBoxMenuItem.checkIcon=com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon
CheckBoxMenuItem.arrowIcon=com.formdev.flatlaf.icons.FlatMenuItemArrowIcon CheckBoxMenuItem.arrowIcon=com.formdev.flatlaf.icons.FlatMenuItemArrowIcon
CheckBoxMenuItem.margin=2,2,2,2 CheckBoxMenuItem.margin=2,2,2,2
CheckBoxMenuItem.opaque=false
CheckBoxMenuItem.background=@menuBackground
#---- ColorChooser ---- #---- ColorChooser ----
@@ -216,12 +218,15 @@ Menu.border=com.formdev.flatlaf.ui.FlatMarginBorder
Menu.arrowIcon=com.formdev.flatlaf.icons.FlatMenuArrowIcon Menu.arrowIcon=com.formdev.flatlaf.icons.FlatMenuArrowIcon
Menu.margin=2,2,2,2 Menu.margin=2,2,2,2
Menu.submenuPopupOffsetX={scaledInteger}-4 Menu.submenuPopupOffsetX={scaledInteger}-4
Menu.submenuPopupOffsetY={scaledInteger}-1 Menu.submenuPopupOffsetY={scaledInteger}-4
Menu.opaque=false
Menu.background=@menuBackground
#---- MenuBar ---- #---- MenuBar ----
MenuBar.border=com.formdev.flatlaf.ui.FlatMenuBarBorder MenuBar.border=com.formdev.flatlaf.ui.FlatMenuBarBorder
MenuBar.background=@menuBackground
#---- MenuItem ---- #---- MenuItem ----
@@ -229,6 +234,8 @@ MenuBar.border=com.formdev.flatlaf.ui.FlatMenuBarBorder
MenuItem.border=com.formdev.flatlaf.ui.FlatMarginBorder MenuItem.border=com.formdev.flatlaf.ui.FlatMarginBorder
MenuItem.arrowIcon=com.formdev.flatlaf.icons.FlatMenuItemArrowIcon MenuItem.arrowIcon=com.formdev.flatlaf.icons.FlatMenuItemArrowIcon
MenuItem.margin=2,2,2,2 MenuItem.margin=2,2,2,2
MenuItem.opaque=false
MenuItem.background=@menuBackground
#---- OptionPane ---- #---- OptionPane ----
@@ -265,7 +272,8 @@ PasswordField.placeholderForeground=@disabledText
#---- PopupMenu ---- #---- PopupMenu ----
PopupMenu.border=com.formdev.flatlaf.ui.FlatPopupMenuBorder PopupMenu.border=com.formdev.flatlaf.ui.FlatPopupMenuBorder
PopupMenu.borderInsets=1,1,1,1 PopupMenu.borderInsets=4,1,4,1
PopupMenu.background=@menuBackground
#---- PopupMenuSeparator ---- #---- PopupMenuSeparator ----
@@ -299,6 +307,8 @@ RadioButtonMenuItem.border=com.formdev.flatlaf.ui.FlatMarginBorder
RadioButtonMenuItem.checkIcon=com.formdev.flatlaf.icons.FlatRadioButtonMenuItemIcon RadioButtonMenuItem.checkIcon=com.formdev.flatlaf.icons.FlatRadioButtonMenuItemIcon
RadioButtonMenuItem.arrowIcon=com.formdev.flatlaf.icons.FlatMenuItemArrowIcon RadioButtonMenuItem.arrowIcon=com.formdev.flatlaf.icons.FlatMenuItemArrowIcon
RadioButtonMenuItem.margin=2,2,2,2 RadioButtonMenuItem.margin=2,2,2,2
RadioButtonMenuItem.opaque=false
RadioButtonMenuItem.background=@menuBackground
#---- ScrollBar ---- #---- ScrollBar ----

View File

@@ -28,6 +28,7 @@
@selectionInactiveForeground=@foreground @selectionInactiveForeground=@foreground
@disabledText=#8C8C8C @disabledText=#8C8C8C
@textComponentBackground=#ffffff @textComponentBackground=#ffffff
@menuBackground=#fff
@cellFocusColor=#000000 @cellFocusColor=#000000
@icon=#afafaf @icon=#afafaf