mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 23:37:13 -06:00
MenuBar:
- use derived colors for menu bar hover - use derived colors for menu item selected background - top-level JMenu now uses foreground color from parent JMenuBar This allows changing menu bar background to dark with: UIManager.put( "MenuBar.background", Color.DARK_GRAY ); UIManager.put( "MenuBar.foreground", Color.WHITE ); or menuBar.setBackground( Color.DARK_GRAY ); menuBar.setForeground( Color.WHITE ); (issue #117)
This commit is contained in:
@@ -261,7 +261,9 @@ debug*/
|
|||||||
|
|
||||||
// paint background
|
// paint background
|
||||||
g.setColor( armedOrSelected
|
g.setColor( armedOrSelected
|
||||||
? (isUnderlineSelection() ? underlineSelectionBackground : selectionBackground)
|
? (isUnderlineSelection()
|
||||||
|
? deriveBackground( underlineSelectionBackground )
|
||||||
|
: selectionBackground)
|
||||||
: menuItem.getBackground() );
|
: menuItem.getBackground() );
|
||||||
g.fillRect( 0, 0, width, height );
|
g.fillRect( 0, 0, width, height );
|
||||||
|
|
||||||
@@ -283,12 +285,20 @@ debug*/
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Color deriveBackground( Color background ) {
|
||||||
|
Color baseColor = menuItem.isOpaque()
|
||||||
|
? menuItem.getBackground()
|
||||||
|
: FlatUIUtils.getParentBackground( menuItem );
|
||||||
|
|
||||||
|
return FlatUIUtils.deriveColor( background, baseColor );
|
||||||
|
}
|
||||||
|
|
||||||
protected void paintIcon( Graphics g, Rectangle iconRect, Icon icon ) {
|
protected void paintIcon( Graphics g, Rectangle iconRect, Icon icon ) {
|
||||||
// if checkbox/radiobutton menu item is selected and also has a custom icon,
|
// if checkbox/radiobutton menu item is selected and also has a custom icon,
|
||||||
// then use filled icon background to indicate selection (instead of using checkIcon)
|
// then use filled icon background to indicate selection (instead of using checkIcon)
|
||||||
if( menuItem.isSelected() && checkIcon != null && icon != checkIcon ) {
|
if( menuItem.isSelected() && checkIcon != null && icon != checkIcon ) {
|
||||||
Rectangle r = FlatUIUtils.addInsets( iconRect, scale( checkMargins ) );
|
Rectangle r = FlatUIUtils.addInsets( iconRect, scale( checkMargins ) );
|
||||||
g.setColor( isUnderlineSelection() ? underlineSelectionCheckBackground : checkBackground );
|
g.setColor( deriveBackground( isUnderlineSelection() ? underlineSelectionCheckBackground : checkBackground ) );
|
||||||
g.fillRect( r.x, r.y, r.width, r.height );
|
g.fillRect( r.x, r.y, r.width, r.height );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,7 +313,7 @@ debug*/
|
|||||||
}
|
}
|
||||||
|
|
||||||
int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1;
|
int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1;
|
||||||
Color foreground = menuItem.getForeground();
|
Color foreground = (isTopLevelMenu( menuItem ) ? menuItem.getParent() : menuItem).getForeground();
|
||||||
|
|
||||||
paintText( g, menuItem, textRect, text, mnemonicIndex, menuItem.getFont(),
|
paintText( g, menuItem, textRect, text, mnemonicIndex, menuItem.getFont(),
|
||||||
foreground, isUnderlineSelection() ? foreground : selectionForeground, disabledForeground );
|
foreground, isUnderlineSelection() ? foreground : selectionForeground, disabledForeground );
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ public class FlatMenuUI
|
|||||||
if( model.isRollover() && !model.isArmed() && !model.isSelected() &&
|
if( model.isRollover() && !model.isArmed() && !model.isSelected() &&
|
||||||
model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() )
|
model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() )
|
||||||
{
|
{
|
||||||
g.setColor( FlatUIUtils.deriveColor( hoverBackground, menuItem.getBackground() ) );
|
g.setColor( deriveBackground( hoverBackground ) );
|
||||||
g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() );
|
g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() );
|
||||||
} else
|
} else
|
||||||
super.paintBackground( g, selectionBackground );
|
super.paintBackground( g, selectionBackground );
|
||||||
|
|||||||
@@ -29,9 +29,9 @@
|
|||||||
@disabledText=#777777
|
@disabledText=#777777
|
||||||
@textComponentBackground=#45494A
|
@textComponentBackground=#45494A
|
||||||
@menuBackground=darken(@background,5%)
|
@menuBackground=darken(@background,5%)
|
||||||
@menuHoverBackground=lighten(@menuBackground,10%)
|
@menuHoverBackground=lighten(@menuBackground,10%,derived)
|
||||||
@menuCheckBackground=lighten(@menuBackground,10%)
|
@menuCheckBackground=lighten(@menuBackground,10%,derived)
|
||||||
@menuCheckHoverBackground=lighten(@menuBackground,20%)
|
@menuCheckHoverBackground=lighten(@menuBackground,20%,derived)
|
||||||
@cellFocusColor=#000000
|
@cellFocusColor=#000000
|
||||||
@icon=#adadad
|
@icon=#adadad
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,9 @@
|
|||||||
@disabledText=#8C8C8C
|
@disabledText=#8C8C8C
|
||||||
@textComponentBackground=#ffffff
|
@textComponentBackground=#ffffff
|
||||||
@menuBackground=#fff
|
@menuBackground=#fff
|
||||||
@menuHoverBackground=darken(@menuBackground,10%)
|
@menuHoverBackground=darken(@menuBackground,10%,derived)
|
||||||
@menuCheckBackground=darken(@menuBackground,10%)
|
@menuCheckBackground=darken(@menuBackground,10%,derived)
|
||||||
@menuCheckHoverBackground=darken(@menuBackground,20%)
|
@menuCheckHoverBackground=darken(@menuBackground,20%,derived)
|
||||||
@cellFocusColor=#000000
|
@cellFocusColor=#000000
|
||||||
@icon=#afafaf
|
@icon=#afafaf
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.testing;
|
package com.formdev.flatlaf.testing;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
@@ -23,6 +24,7 @@ import java.awt.Graphics;
|
|||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.plaf.ColorUIResource;
|
||||||
import com.formdev.flatlaf.FlatLaf;
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
import net.miginfocom.swing.*;
|
import net.miginfocom.swing.*;
|
||||||
@@ -69,6 +71,13 @@ public class FlatMenusTest
|
|||||||
FlatLaf.updateUI();
|
FlatLaf.updateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void popupMenubackgroundChanged() {
|
||||||
|
UIManager.put( "PopupMenu.background", popupMenubackgroundCheckBox.isSelected()
|
||||||
|
? new ColorUIResource( Color.yellow )
|
||||||
|
: null );
|
||||||
|
FlatLaf.updateUI();
|
||||||
|
}
|
||||||
|
|
||||||
private void showPopupMenuButtonActionPerformed(ActionEvent e) {
|
private void showPopupMenuButtonActionPerformed(ActionEvent e) {
|
||||||
Component invoker = (Component) e.getSource();
|
Component invoker = (Component) e.getSource();
|
||||||
PopupMenu popupMenu = new PopupMenu();
|
PopupMenu popupMenu = new PopupMenu();
|
||||||
@@ -207,6 +216,7 @@ public class FlatMenusTest
|
|||||||
JButton showPopupMenuButton = new JButton();
|
JButton showPopupMenuButton = new JButton();
|
||||||
armedCheckBox = new JCheckBox();
|
armedCheckBox = new JCheckBox();
|
||||||
underlineCheckBox = new JCheckBox();
|
underlineCheckBox = new JCheckBox();
|
||||||
|
popupMenubackgroundCheckBox = new JCheckBox();
|
||||||
|
|
||||||
//======== this ========
|
//======== this ========
|
||||||
setLayout(new MigLayout(
|
setLayout(new MigLayout(
|
||||||
@@ -222,6 +232,7 @@ public class FlatMenusTest
|
|||||||
"[top]" +
|
"[top]" +
|
||||||
"[]" +
|
"[]" +
|
||||||
"[]" +
|
"[]" +
|
||||||
|
"[]" +
|
||||||
"[]"));
|
"[]"));
|
||||||
|
|
||||||
//---- menuBarLabel ----
|
//---- menuBarLabel ----
|
||||||
@@ -738,6 +749,11 @@ public class FlatMenusTest
|
|||||||
underlineCheckBox.addActionListener(e -> underlineChanged());
|
underlineCheckBox.addActionListener(e -> underlineChanged());
|
||||||
add(underlineCheckBox, "cell 0 4 2 1");
|
add(underlineCheckBox, "cell 0 4 2 1");
|
||||||
|
|
||||||
|
//---- popupMenubackgroundCheckBox ----
|
||||||
|
popupMenubackgroundCheckBox.setText("yellow popup menu background");
|
||||||
|
popupMenubackgroundCheckBox.addActionListener(e -> popupMenubackgroundChanged());
|
||||||
|
add(popupMenubackgroundCheckBox, "cell 0 5 2 1");
|
||||||
|
|
||||||
//---- buttonGroup1 ----
|
//---- buttonGroup1 ----
|
||||||
ButtonGroup buttonGroup1 = new ButtonGroup();
|
ButtonGroup buttonGroup1 = new ButtonGroup();
|
||||||
buttonGroup1.add(radioButtonMenuItem5);
|
buttonGroup1.add(radioButtonMenuItem5);
|
||||||
@@ -756,6 +772,7 @@ public class FlatMenusTest
|
|||||||
private JCheckBox accelCheckBox;
|
private JCheckBox accelCheckBox;
|
||||||
private JCheckBox armedCheckBox;
|
private JCheckBox armedCheckBox;
|
||||||
private JCheckBox underlineCheckBox;
|
private JCheckBox underlineCheckBox;
|
||||||
|
private JCheckBox popupMenubackgroundCheckBox;
|
||||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||||
|
|
||||||
//---- class PopupMenu ----------------------------------------------------
|
//---- class PopupMenu ----------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8"
|
JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
|
||||||
|
|
||||||
new FormModel {
|
new FormModel {
|
||||||
contentType: "form/swing"
|
contentType: "form/swing"
|
||||||
@@ -9,7 +9,7 @@ new FormModel {
|
|||||||
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||||
"$layoutConstraints": "ltr,insets dialog,hidemode 3"
|
"$layoutConstraints": "ltr,insets dialog,hidemode 3"
|
||||||
"$columnConstraints": "[125][][][][]"
|
"$columnConstraints": "[125][][][][]"
|
||||||
"$rowConstraints": "[][top][][][]"
|
"$rowConstraints": "[][top][][][][]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "this"
|
name: "this"
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
@@ -561,6 +561,16 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 4 2 1"
|
"value": "cell 0 4 2 1"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
|
name: "popupMenubackgroundCheckBox"
|
||||||
|
"text": "yellow popup menu background"
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.variableLocal": false
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "popupMenubackgroundChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 0 5 2 1"
|
||||||
|
} )
|
||||||
}, new FormLayoutConstraints( null ) {
|
}, new FormLayoutConstraints( null ) {
|
||||||
"location": new java.awt.Point( 0, 0 )
|
"location": new java.awt.Point( 0, 0 )
|
||||||
"size": new java.awt.Dimension( 790, 380 )
|
"size": new java.awt.Dimension( 790, 380 )
|
||||||
|
|||||||
@@ -515,7 +515,7 @@ MenuBar.borderColor #515151 javax.swing.plaf.ColorUIResource [UI]
|
|||||||
MenuBar.font [active] $defaultFont [UI]
|
MenuBar.font [active] $defaultFont [UI]
|
||||||
MenuBar.foreground #bbbbbb javax.swing.plaf.ColorUIResource [UI]
|
MenuBar.foreground #bbbbbb javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuBar.highlight #242424 javax.swing.plaf.ColorUIResource [UI]
|
MenuBar.highlight #242424 javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuBar.hoverBackground #484c4f javax.swing.plaf.ColorUIResource [UI]
|
MenuBar.hoverBackground #484c4f com.formdev.flatlaf.util.DerivedColor [UI] lighten(10% autoInverse)
|
||||||
MenuBar.itemMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
|
MenuBar.itemMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
|
||||||
MenuBar.shadow #646464 javax.swing.plaf.ColorUIResource [UI]
|
MenuBar.shadow #646464 javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuBar.windowBindings length=2 [Ljava.lang.Object;
|
MenuBar.windowBindings length=2 [Ljava.lang.Object;
|
||||||
@@ -535,7 +535,7 @@ MenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenu
|
|||||||
MenuItem.background #303234 javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.background #303234 javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI]
|
MenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI]
|
||||||
MenuItem.borderPainted true
|
MenuItem.borderPainted true
|
||||||
MenuItem.checkBackground #484c4f javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.checkBackground #484c4f com.formdev.flatlaf.util.DerivedColor [UI] lighten(10% autoInverse)
|
||||||
MenuItem.checkMargins 2,2,2,2 javax.swing.plaf.InsetsUIResource [UI]
|
MenuItem.checkMargins 2,2,2,2 javax.swing.plaf.InsetsUIResource [UI]
|
||||||
MenuItem.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuItem.font [active] $defaultFont [UI]
|
MenuItem.font [active] $defaultFont [UI]
|
||||||
@@ -549,8 +549,8 @@ MenuItem.selectionBackground #4b6eaf javax.swing.plaf.ColorUIResource [UI]
|
|||||||
MenuItem.selectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.selectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuItem.textAcceleratorGap 24
|
MenuItem.textAcceleratorGap 24
|
||||||
MenuItem.textNoAcceleratorGap 6
|
MenuItem.textNoAcceleratorGap 6
|
||||||
MenuItem.underlineSelectionBackground #484c4f javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.underlineSelectionBackground #484c4f com.formdev.flatlaf.util.DerivedColor [UI] lighten(10% autoInverse)
|
||||||
MenuItem.underlineSelectionCheckBackground #616569 javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.underlineSelectionCheckBackground #616569 com.formdev.flatlaf.util.DerivedColor [UI] lighten(20% autoInverse)
|
||||||
MenuItem.underlineSelectionColor #4a88c7 javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.underlineSelectionColor #4a88c7 javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuItem.underlineSelectionHeight 3
|
MenuItem.underlineSelectionHeight 3
|
||||||
|
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ MenuBar.borderColor #cdcdcd javax.swing.plaf.ColorUIResource [UI]
|
|||||||
MenuBar.font [active] $defaultFont [UI]
|
MenuBar.font [active] $defaultFont [UI]
|
||||||
MenuBar.foreground #000000 javax.swing.plaf.ColorUIResource [UI]
|
MenuBar.foreground #000000 javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuBar.highlight #ffffff javax.swing.plaf.ColorUIResource [UI]
|
MenuBar.highlight #ffffff javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuBar.hoverBackground #e6e6e6 javax.swing.plaf.ColorUIResource [UI]
|
MenuBar.hoverBackground #e6e6e6 com.formdev.flatlaf.util.DerivedColor [UI] darken(10% autoInverse)
|
||||||
MenuBar.itemMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
|
MenuBar.itemMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
|
||||||
MenuBar.shadow #c4c4c4 javax.swing.plaf.ColorUIResource [UI]
|
MenuBar.shadow #c4c4c4 javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuBar.windowBindings length=2 [Ljava.lang.Object;
|
MenuBar.windowBindings length=2 [Ljava.lang.Object;
|
||||||
@@ -540,7 +540,7 @@ MenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenu
|
|||||||
MenuItem.background #ffffff javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.background #ffffff javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI]
|
MenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI]
|
||||||
MenuItem.borderPainted true
|
MenuItem.borderPainted true
|
||||||
MenuItem.checkBackground #e6e6e6 javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.checkBackground #e6e6e6 com.formdev.flatlaf.util.DerivedColor [UI] darken(10% autoInverse)
|
||||||
MenuItem.checkMargins 2,2,2,2 javax.swing.plaf.InsetsUIResource [UI]
|
MenuItem.checkMargins 2,2,2,2 javax.swing.plaf.InsetsUIResource [UI]
|
||||||
MenuItem.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuItem.font [active] $defaultFont [UI]
|
MenuItem.font [active] $defaultFont [UI]
|
||||||
@@ -554,8 +554,8 @@ MenuItem.selectionBackground #2675bf javax.swing.plaf.ColorUIResource [UI]
|
|||||||
MenuItem.selectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.selectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuItem.textAcceleratorGap 24
|
MenuItem.textAcceleratorGap 24
|
||||||
MenuItem.textNoAcceleratorGap 6
|
MenuItem.textNoAcceleratorGap 6
|
||||||
MenuItem.underlineSelectionBackground #e6e6e6 javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.underlineSelectionBackground #e6e6e6 com.formdev.flatlaf.util.DerivedColor [UI] darken(10% autoInverse)
|
||||||
MenuItem.underlineSelectionCheckBackground #cccccc javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.underlineSelectionCheckBackground #cccccc com.formdev.flatlaf.util.DerivedColor [UI] darken(20% autoInverse)
|
||||||
MenuItem.underlineSelectionColor #4083c9 javax.swing.plaf.ColorUIResource [UI]
|
MenuItem.underlineSelectionColor #4083c9 javax.swing.plaf.ColorUIResource [UI]
|
||||||
MenuItem.underlineSelectionHeight 3
|
MenuItem.underlineSelectionHeight 3
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user