Menus: scroll large menus using mouse wheel or up/down arrows (issue #225)

This commit is contained in:
Karl Tauber
2022-03-14 11:41:05 +01:00
parent f6b42754de
commit fef6ae7ff7
16 changed files with 384 additions and 3 deletions

View File

@@ -737,6 +737,8 @@ PopupMenu.borderInsets 4,1,4,1 javax.swing.plaf.InsetsUIResource [UI]
PopupMenu.consumeEventOnClose false
PopupMenu.font [active] $defaultFont [UI]
PopupMenu.foreground #bbbbbb HSL 0 0 73 javax.swing.plaf.ColorUIResource [UI]
PopupMenu.hoverScrollArrowBackground #484c4e HSL 200 4 29 javax.swing.plaf.ColorUIResource [UI]
PopupMenu.scrollArrowColor #9b9b9b HSL 0 0 61 javax.swing.plaf.ColorUIResource [UI]
#---- PopupMenuSeparator ----

View File

@@ -742,6 +742,8 @@ PopupMenu.borderInsets 4,1,4,1 javax.swing.plaf.InsetsUIResource [UI]
PopupMenu.consumeEventOnClose false
PopupMenu.font [active] $defaultFont [UI]
PopupMenu.foreground #000000 HSL 0 0 0 javax.swing.plaf.ColorUIResource [UI]
PopupMenu.hoverScrollArrowBackground #e5e5e5 HSL 0 0 90 javax.swing.plaf.ColorUIResource [UI]
PopupMenu.scrollArrowColor #666666 HSL 0 0 40 javax.swing.plaf.ColorUIResource [UI]
#---- PopupMenuSeparator ----

View File

@@ -752,6 +752,8 @@ PopupMenu.borderInsets 4,1,4,1 javax.swing.plaf.InsetsUIResource [UI]
PopupMenu.consumeEventOnClose false
PopupMenu.font [active] $defaultFont [UI]
PopupMenu.foreground #ff0000 HSL 0 100 50 javax.swing.plaf.ColorUIResource [UI]
PopupMenu.hoverScrollArrowBackground #00ff00 HSL 120 100 50 javax.swing.plaf.ColorUIResource [UI]
PopupMenu.scrollArrowColor #0000ff HSL 240 100 50 javax.swing.plaf.ColorUIResource [UI]
#---- PopupMenuSeparator ----

View File

@@ -80,13 +80,24 @@ public class FlatMenusTest
FlatLaf.updateUI();
}
private void showPopupMenuButtonActionPerformed(ActionEvent e) {
private void showPopupMenuButton(ActionEvent e) {
Component invoker = (Component) e.getSource();
PopupMenu popupMenu = new PopupMenu();
popupMenu.applyComponentOrientation( getComponentOrientation() );
popupMenu.show( invoker, 0, invoker.getHeight() );
}
private void showScrollingPopupMenu(ActionEvent e) {
Component invoker = (Component) e.getSource();
JPopupMenu popupMenu = new JPopupMenu();
for( int i = 1; i <= 100; i++ ) {
popupMenu.add( "menu item " + i + (i % 5 == 0 ? " test" : "") )
.addActionListener( e2 -> System.out.println( ((JMenuItem)e2.getSource()).getText() ) );
}
popupMenu.applyComponentOrientation( getComponentOrientation() );
popupMenu.show( invoker, 0, invoker.getHeight() );
}
private void largerChanged() {
LargerMenuItem.useLargerSize = largerCheckBox.isSelected();
menuBar2.revalidate();
@@ -230,6 +241,7 @@ public class FlatMenusTest
JRadioButtonMenuItem radioButtonMenuItem11 = new JRadioButtonMenuItem();
JLabel popupMenuLabel = new JLabel();
JButton showPopupMenuButton = new JButton();
showScrollingPopupMenuButton = new JButton();
armedCheckBox = new JCheckBox();
underlineCheckBox = new JCheckBox();
popupMenubackgroundCheckBox = new JCheckBox();
@@ -839,9 +851,14 @@ public class FlatMenusTest
//---- showPopupMenuButton ----
showPopupMenuButton.setText("show JPopupMenu");
showPopupMenuButton.addActionListener(e -> showPopupMenuButtonActionPerformed(e));
showPopupMenuButton.addActionListener(e -> showPopupMenuButton(e));
add(showPopupMenuButton, "cell 1 2");
//---- showScrollingPopupMenuButton ----
showScrollingPopupMenuButton.setText("show scrolling JPopupMenu");
showScrollingPopupMenuButton.addActionListener(e -> showScrollingPopupMenu(e));
add(showScrollingPopupMenuButton, "cell 2 2");
//---- armedCheckBox ----
armedCheckBox.setText("armed");
armedCheckBox.setMnemonic('A');
@@ -884,6 +901,7 @@ public class FlatMenusTest
private JMenuBar menuBar2;
private JCheckBox largerCheckBox;
private JCheckBox accelCheckBox;
private JButton showScrollingPopupMenuButton;
private JCheckBox armedCheckBox;
private JCheckBox underlineCheckBox;
private JCheckBox popupMenubackgroundCheckBox;

View File

@@ -629,10 +629,20 @@ new FormModel {
add( new FormComponent( "javax.swing.JButton" ) {
name: "showPopupMenuButton"
"text": "show JPopupMenu"
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showPopupMenuButtonActionPerformed", true ) )
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showPopupMenuButton", true ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "showScrollingPopupMenuButton"
"text": "show scrolling JPopupMenu"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showScrollingPopupMenu", true ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 2"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "armedCheckBox"
"text": "armed"

View File

@@ -276,6 +276,8 @@ Popup.dropShadowInsets = -6,6,6,6
#---- PopupMenu ----
PopupMenu.borderColor = #00f
PopupMenu.scrollArrowColor = #00f
PopupMenu.hoverScrollArrowBackground = #0f0
#---- PopupMenuSeparator ----