mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17:13 -06:00
Merge PR #415: MenuItem: paint the selected icon when the item is selected
This commit is contained in:
@@ -61,6 +61,7 @@ FlatLaf Change Log
|
||||
- Slider: Support specifying width of thumb border (see UI value
|
||||
`Slider.thumbBorderWidth`).
|
||||
- TabbedPane: Optionally paint selected tab as card. (PR #343)
|
||||
- MenuItem: Paint the selected icon when the item is selected. (PR #415)
|
||||
- Added more color functions to class `ColorFunctions` for easy use in
|
||||
applications: `lighten()`, `darken()`, `saturate()`, `desaturate()`, `spin()`,
|
||||
`tint()`, `shade()` and `luma()`.
|
||||
|
||||
@@ -444,6 +444,10 @@ debug*/
|
||||
htmlView.paint( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ), textRect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if either the menu item is armed (mouse over item)
|
||||
* or it is a {@code JMenu} and selected (shows submenu).
|
||||
*/
|
||||
protected static boolean isArmedOrSelected( JMenuItem menuItem ) {
|
||||
return menuItem.isArmed() || (menuItem instanceof JMenu && menuItem.isSelected());
|
||||
}
|
||||
@@ -474,6 +478,12 @@ debug*/
|
||||
return pressedIcon;
|
||||
}
|
||||
|
||||
if( isArmedOrSelected( menuItem ) ) {
|
||||
Icon selectedIcon = menuItem.getSelectedIcon();
|
||||
if( selectedIcon != null )
|
||||
return selectedIcon;
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,9 @@ public class FlatMenusTest
|
||||
FlatMenusTest.MenuWithAccelerator menuWithAccelerator2 = new FlatMenusTest.MenuWithAccelerator();
|
||||
JMenuItem menuItem40 = new JMenuItem();
|
||||
JMenuItem menuItem39 = new JMenuItem();
|
||||
JMenu menu12 = new JMenu();
|
||||
JMenuItem menuItem41 = new JMenuItem();
|
||||
JMenuItem menuItem42 = new JMenuItem();
|
||||
menuBar2 = new JMenuBar();
|
||||
JMenu menu8 = new JMenu();
|
||||
FlatMenusTest.LargerMenuItem menuItem13 = new FlatMenusTest.LargerMenuItem();
|
||||
@@ -377,6 +380,25 @@ public class FlatMenusTest
|
||||
menuWithAccelerator1.add(menuItem39);
|
||||
}
|
||||
menuBar1.add(menuWithAccelerator1);
|
||||
|
||||
//======== menu12 ========
|
||||
{
|
||||
menu12.setText("icons");
|
||||
|
||||
//---- menuItem41 ----
|
||||
menuItem41.setText("selected icon");
|
||||
menuItem41.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-cut.png")));
|
||||
menuItem41.setSelectedIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-show_dark.png")));
|
||||
menu12.add(menuItem41);
|
||||
|
||||
//---- menuItem42 ----
|
||||
menuItem42.setText("disabled icon");
|
||||
menuItem42.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-cut.png")));
|
||||
menuItem42.setDisabledIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste.png")));
|
||||
menuItem42.setEnabled(false);
|
||||
menu12.add(menuItem42);
|
||||
}
|
||||
menuBar1.add(menu12);
|
||||
}
|
||||
add(menuBar1, "cell 1 0 2 1,growx");
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
JFDML JFormDesigner: "7.0.3.1.342" Java: "15" encoding: "UTF-8"
|
||||
JFDML JFormDesigner: "7.0.5.0.404" Java: "16" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
@@ -149,6 +149,23 @@ new FormModel {
|
||||
"accelerator": #KeyStroke0
|
||||
} )
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
|
||||
name: "menu12"
|
||||
"text": "icons"
|
||||
add( new FormComponent( "javax.swing.JMenuItem" ) {
|
||||
name: "menuItem41"
|
||||
"text": "selected icon"
|
||||
"icon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-cut.png" )
|
||||
"selectedIcon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-show_dark.png" )
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JMenuItem" ) {
|
||||
name: "menuItem42"
|
||||
"text": "disabled icon"
|
||||
"icon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-cut.png" )
|
||||
"disabledIcon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste.png" )
|
||||
"enabled": false
|
||||
} )
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 0 2 1,growx"
|
||||
} )
|
||||
|
||||
Reference in New Issue
Block a user