当我将我的JMenuBar移动到Mac的屏幕菜单栏上时,它会在我的窗口中留下一些菜单所在的空白区域;我需要删除这些空间。我正在使用
System.setProperty("apple.laf.useScreenMenuBar", "true")将我的JMenuBar移到屏幕菜单栏。我的一位使用Mac的朋友报告说,如果我没有设置这个属性,就会留下一些难看的垂直空间,菜单就会驻留在那里。解决此问题的最佳方法是什么?
编辑:这是我的源码中的一个例子:
public static void main(String[] args) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Name");
JFrame frame = new JFrame("Gabby");
final DesktopMain dm = new DesktopMain();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(dm);
frame.setSize(160, 144);
frame.setLocationRelativeTo(null);
frame.setIgnoreRepaint(true);
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
menuBar.add(fileMenu);
// Populating the menu bar code goes here
frame.setJMenuBar(menuBar);
frame.setVisible(true);
}发布于 2016-11-27 09:02:30
对于Java 8,请使用以下代码
System.setProperty("apple.awt.application.name", "My app");https://stackoverflow.com/questions/8955638
复制相似问题