java移动菜单_java – 如何将我的JMenuBar移动到Mac OS X上的屏幕菜单栏?

根据完成的时间,在程序启动后设置属性可能为时已晚,无法生效.而是在启动时添加设置.

java -Dapple.laf.useScreenMenuBar=true -jar MyApplication.jar

Properties

apple.laf.useScreenMenuBar

true

...

附录:如下所示,使用@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);

}

});

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值