当我将我移动JMenuBar到Mac OS X上的屏幕菜单栏时,它会留下一些空白区域,菜单将出现在我的窗口中; 我需要删除那个空间.我在用
System.setProperty("apple.laf.useScreenMenuBar", "true")
Run Code Online (Sandbox Code Playgroud)
将我移动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);
}
Run Code Online (Sandbox Code Playgroud) 好的,所以我之前已经完成了Swing应用程序,并且我知道如果你想为应用程序菜单显示一个不同的名称(通常具有"首选项"和"退出"选项的Mac上的那个),你必须使用:System.setProperty("com.apple.mrj.application.apple.menu.about.name", "App name");它必须在创建JFrame之前执行.我已经完成了这个,但它继续显示我的Main类的名称作为菜单名称,就好像我根本没有编写那行代码.我搜索了这个问题,但找不到任何有用的东西,然后我就在这里搜索,但是每个遇到类似问题的人都在运行Java 1.5,1.6或1.7.所以我想也许它与我目前的Java版本1.8有关.
这个,这个,这个没用.这个,这个和这个要么发送给我过时的信息,要么链接不再起作用了.另外,我正在运行Mac 10.8.
任何建议/答案将不胜感激.
更新:
这是我原来的代码:
package bouncing_off_axes;
/**
* This is the driver class of this program.
*
* @author Mason
*
*/
public class Main {
/**
* The driving method.
*
* @param args
*/
public static void main(String[] args) {
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Physics Engine Practice - Bouncing Balls");
SimulationController view = new SimulationController("Test");
}
}
Run Code Online (Sandbox Code Playgroud)
以下是垃圾邮件提供给其他人的解决方案:
package bouncing_off_axes;
import java.awt.Color;
import …Run Code Online (Sandbox Code Playgroud)