您可能需要向我们提供更多信息,也许是一些屏幕截图,说明您所拥有的以及您正在努力实现的目标,这menu.setComponentOrientation()
对我来说似乎工作得很好......
我明白了
运行这个
import javax.swing.*;
import java.awt.*;
public class MenuTest extends JFrame{
public static void display()
{
JFrame frame = new JFrame();
frame.setSize(400,400);
frame.setLayout(new GridLayout(6,1));
JMenuBar menuBar = new JMenuBar();
menuBar.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
JMenu jMenu1 = new JMenu("Menu1");
jMenu1.setMinimumSize(new Dimension(200, 20));
jMenu1.setMaximumSize(new Dimension(200, 20));
jMenu1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
JMenu jMenu2 = new JMenu("Menu2");
jMenu2.setMinimumSize(new Dimension(200, 20));
jMenu2.setMaximumSize(new Dimension(200, 20));
JMenuItem menuItem1 = new JMenuItem("Item1");
JMenuItem menuItem2 = new JMenuItem("Item2");
menuItem1.setMinimumSize(new Dimension(200, 20));
menuItem1.setMaximumSize(new Dimension(200, 20));
menuItem1.setPreferredSize(new Dimension(200, 20));
menuItem1.setSize(new Dimension(200, 20));
menuItem2.setMinimumSize(new Dimension(200, 20));
menuItem2.setMaximumSize(new Dimension(200, 20));
menuItem1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
menuItem2.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
jMenu1.setHorizontalAlignment(JMenu.TRAILING);
jMenu1.add(menuItem1);
jMenu1.add(menuItem2);
menuBar.add(jMenu1);
menuBar.add(jMenu2);
menuBar.setSize(frame.getWidth(), 20);
frame.add(menuBar);
frame.setVisible(true);
}
public static void main(String[] args)
{
EventQueue.invokeLater(
new Runnable() {
@Override
public void run() {
MenuTest.display();
}
}
);
}
}