Menus: added gap between accelerator and arrow in menu items (issue #91)

This commit is contained in:
Karl Tauber
2020-05-02 19:16:33 +02:00
parent 099dd87241
commit a2541a9659
12 changed files with 135 additions and 53 deletions

View File

@@ -145,6 +145,10 @@ public class FlatMenusTest
JMenu menu6 = new JMenu();
JMenuItem menuItem5 = new JMenuItem();
JMenuItem menuItem6 = new JMenuItem();
FlatMenusTest.MenuWithAccelerator menuWithAccelerator1 = new FlatMenusTest.MenuWithAccelerator();
FlatMenusTest.MenuWithAccelerator menuWithAccelerator2 = new FlatMenusTest.MenuWithAccelerator();
JMenuItem menuItem40 = new JMenuItem();
JMenuItem menuItem39 = new JMenuItem();
menuBar2 = new JMenuBar();
JMenu menu8 = new JMenu();
FlatMenusTest.LargerMenuItem menuItem13 = new FlatMenusTest.LargerMenuItem();
@@ -322,6 +326,29 @@ public class FlatMenusTest
menu6.add(menuItem6);
}
menuBar1.add(menu6);
//======== menuWithAccelerator1 ========
{
menuWithAccelerator1.setText("text");
menuWithAccelerator1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0));
//======== menuWithAccelerator2 ========
{
menuWithAccelerator2.setText("text");
menuWithAccelerator2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK));
//---- menuItem40 ----
menuItem40.setText("text");
menuWithAccelerator2.add(menuItem40);
}
menuWithAccelerator1.add(menuWithAccelerator2);
//---- menuItem39 ----
menuItem39.setText("text");
menuItem39.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK));
menuWithAccelerator1.add(menuItem39);
}
menuBar1.add(menuWithAccelerator1);
}
add(menuBar1, "cell 1 0 2 1,growx");
@@ -808,4 +835,28 @@ public class FlatMenusTest
g.drawLine( 0, getHeight(), getWidth(), getHeight() );
}
}
//---- class MenuWithAccelerator ------------------------------------------
public static class MenuWithAccelerator
extends JMenu
{
private KeyStroke accelerator;
@Override
public KeyStroke getAccelerator() {
return accelerator;
}
@Override
public void setAccelerator( KeyStroke keyStroke ) {
KeyStroke oldAccelerator = accelerator;
this.accelerator = keyStroke;
revalidate();
repaint();
firePropertyChange( "accelerator", oldAccelerator, accelerator );
}
}
}

View File

@@ -120,6 +120,25 @@ new FormModel {
"text": "text"
} )
} )
add( new FormContainer( "com.formdev.flatlaf.testing.FlatMenusTest$MenuWithAccelerator", new FormLayoutManager( class javax.swing.JMenu ) ) {
name: "menuWithAccelerator1"
"text": "text"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 122, 0, false )
add( new FormContainer( "com.formdev.flatlaf.testing.FlatMenusTest$MenuWithAccelerator", new FormLayoutManager( class javax.swing.JMenu ) ) {
name: "menuWithAccelerator2"
"text": "text"
"accelerator": &KeyStroke0 static javax.swing.KeyStroke getKeyStroke( 72, 130, false )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem40"
"text": "text"
} )
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem39"
"text": "text"
"accelerator": #KeyStroke0
} )
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 0 2 1,growx"
} )
@@ -345,7 +364,7 @@ new FormModel {
add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) {
name: "checkBoxMenuItem1"
"text": "<html>en<b>abl</b>ed</html>"
"accelerator": &KeyStroke0 static javax.swing.KeyStroke getKeyStroke( 112, 0, false )
"accelerator": &KeyStroke1 static javax.swing.KeyStroke getKeyStroke( 112, 0, false )
"mnemonic": 65
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2"
@@ -359,7 +378,7 @@ new FormModel {
add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) {
name: "radioButtonMenuItem1"
"text": "<html>en<b color=\"red\">abl</b><i color=\"blue\">ed</i></html>"
"accelerator": #KeyStroke0
"accelerator": #KeyStroke1
"mnemonic": 66
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 3"
@@ -406,7 +425,7 @@ new FormModel {
name: "checkBoxMenuItem2"
"text": "disabled"
"enabled": false
"accelerator": #KeyStroke0
"accelerator": #KeyStroke1
"mnemonic": 83
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2"
@@ -415,7 +434,7 @@ new FormModel {
name: "radioButtonMenuItem2"
"text": "disabled"
"enabled": false
"accelerator": #KeyStroke0
"accelerator": #KeyStroke1
"mnemonic": 76
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 3"
@@ -441,7 +460,7 @@ new FormModel {
name: "menuItem3"
"text": "selected"
"selected": true
"accelerator": #KeyStroke0
"accelerator": #KeyStroke1
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 1"
} )
@@ -449,7 +468,7 @@ new FormModel {
name: "checkBoxMenuItem3"
"text": "selected"
"selected": true
"accelerator": #KeyStroke0
"accelerator": #KeyStroke1
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2"
} )
@@ -457,7 +476,7 @@ new FormModel {
name: "radioButtonMenuItem3"
"text": "selected"
"selected": true
"accelerator": #KeyStroke0
"accelerator": #KeyStroke1
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 3"
} )
@@ -483,7 +502,7 @@ new FormModel {
"text": "selected disabled"
"selected": true
"enabled": false
"accelerator": #KeyStroke0
"accelerator": #KeyStroke1
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 1"
} )
@@ -492,7 +511,7 @@ new FormModel {
"text": "selected disabled"
"enabled": false
"selected": true
"accelerator": #KeyStroke0
"accelerator": #KeyStroke1
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2"
} )
@@ -501,7 +520,7 @@ new FormModel {
"text": "selected disabled"
"enabled": false
"selected": true
"accelerator": #KeyStroke0
"accelerator": #KeyStroke1
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 3"
} )