我在Java应用程序中使用右到左菜单
我在所有JMenuBar
,JMenu
& JMenuItem
元素使它们从右到左:
jmenubar.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
jmenu1.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
jmenuitem1.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
现在问题是JMenuItem
的文字正确对齐但其键盘加速器未对齐,因为此图像显示(F2& F3已经出局)视图和其他人没有对齐左):
问题:如何修复从右到左JMenuItem
的加速器对齐方式?
对于SSCCE:
本规范产生了问题:
public class test{
public static void main(String[] args){
try{
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
javax.swing.JFrame frame = new javax.swing.JFrame("test");
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
javax.swing.JMenuBar menubar = new javax.swing.JMenuBar();
javax.swing.JMenu jmenu1 = new javax.swing.JMenu("\u0645\u0646\u0648");
javax.swing.JMenuItem jmenuitem1 = new javax.swing.JMenuItem("\u0645\u0646\u0648 \u06F1");
javax.swing.JMenuItem jmenuitem2 = new javax.swing.JMenuItem("\u0645\u0646\u0648 \u06F2");
javax.swing.JMenuItem jmenuitem3 = new javax.swing.JMenuItem("\u0645\u0646\u0648 \u06F3");
javax.swing.JMenuItem jmenuitem4 = new javax.swing.JMenuItem("\u0645\u0646\u0648 \u06F4");
jmenuitem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, 0));
jmenuitem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, 0));
jmenuitem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK|java.awt.event.InputEvent.ALT_MASK));
jmenuitem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
menubar.applyComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
jmenu1.applyComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
jmenuitem1.applyComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
jmenuitem2.applyComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
jmenuitem3.applyComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
jmenuitem4.applyComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
jmenu1.setFont(new java.awt.Font("Times New Roman", 0, 15));
jmenuitem1.setFont(new java.awt.Font("Times New Roman", 0, 15));
jmenuitem2.setFont(new java.awt.Font("Times New Roman", 0, 15));
jmenuitem3.setFont(new java.awt.Font("Times New Roman", 0, 15));
jmenuitem4.setFont(new java.awt.Font("Times New Roman", 0, 15));
frame.setJMenuBar(menubar);
menubar.add(jmenu1);
jmenu1.add(jmenuitem1);
jmenu1.add(jmenuitem2);
jmenu1.add(jmenuitem3);
jmenu1.add(jmenuitem4);
frame.setVisible(true);
frame.pack();
frame.setSize(200,200);
}
});
}catch(java.lang.Exception e){
System.out.println(e.getMessage());
}
}
}