java – 如何将我的JMenuBar移动到Mac OS X上的屏幕菜单栏?
发布时间:2020-12-15 00:47:32 所属栏目:Java 来源:网络整理
导读:当我将JMenuBar移动到Mac OS X上的屏幕菜单栏时,它会留下一些空白区域,菜单将出现在我的窗口中;我需要删除那个空间.我在用 System.setProperty("apple.laf.useScreenMenuBar","true") 将我的JMenuBar移动到屏幕菜单栏.我的朋友使用Mac报告,如果我没有设置该
当我将JMenuBar移动到Mac OS X上的屏幕菜单栏时,它会留下一些空白区域,菜单将出现在我的窗口中;我需要删除那个空间.我在用
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); } 解决方法
根据完成的时间,在程序启动后设置属性可能为时已晚,无法生效.而是在启动时添加设置.
java -Dapple.laf.useScreenMenuBar=true -jar MyApplication.jar 或者,在应用程序包的Info.plist中设置该属性,如Java Deployment Options for Mac OS X,Java Dictionary Info.plist Keys,About Info.plist Keys和Java Runtime System Properties中所述. <key>Properties</key> <dict> <key>apple.laf.useScreenMenuBar</key> <string>true</string> ... </dict> 附录:如下所示,使用@Urs Reupke或我建议的方法不会出现问题.你的(缺失的)DesktopMain可能有问题. import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JPanel; /** @see https://stackoverflow.com/questions/8955638 */ public class NewMain { public static void main(String[] args) { System.setProperty("apple.laf.useScreenMenuBar","true"); System.setProperty( "com.apple.mrj.application.apple.menu.about.name","Name"); EventQueue.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame("Gabby"); final JPanel dm = new JPanel() { @Override public Dimension getPreferredSize() { return new Dimension(320,240); } }; dm.setBorder(BorderFactory.createLineBorder(Color.blue,10)); frame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE); frame.add(dm); frame.pack(); frame.setLocationByPlatform(true); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); frame.setJMenuBar(menuBar); frame.setVisible(true); } }); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 详解如何使用Jersey客户端请求Spring Boot(RESTFul)服务
- 异常:android.os.NetworkOnMainThreadException
- java – 如何在特定位置的ArrayList中插入对象
- 最新的Cassandra是否支持openJDK?
- 如何通过java获取文件名和扩展名
- MD5在Java中使用ISO-8859-1字符串哈希
- java – 从BufferedImage到SWT Image的转换
- java – Hibernate合并丢失数据
- java – 带有自定义FileSystemView实现的JFileChooser
- java – Gradle – 使用插件将配置应用于所有项目
推荐文章
站长推荐
- java – 请推荐在Spring MVC 3应用程序中使用的视
- java – 将新行放入mysql表时要向Response.creat
- JavaFX 2.0激活菜单,如MenuItem
- Android的Volley网络Get/Post请求包实例代码
- java – Spring 3 applicationContext-security-
- java – 将图像放在webview中并适合宽度
- Java编程接口调用的作用及代码分享
- 用于运行应用程序的Java 9 REPL
- java – 如何将EclipseLink对象导出到XML
- java – Quartz StatefulJob / non-StatefulJob
热点阅读