Reputation: 1260
After implementing Mac OS X look and feel, just after reading
I noticed two problems.
JMenuBar
is now shown in the Mac Bar, if I click on a JMenuItem
, no event is called. Using: System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Name");
is the name given in the cration of the project.The interface:
I'm trying Java OS X Lion Set application name doesn't work to solve the second problem. I' can't launch the jar from command line, so I'm using Martjin answer.
Upvotes: 3
Views: 4060
Reputation: 205785
Starting from the example cited,
The JMenuItem
listener prints "Here" when File > Item
is clicked.
The about.name
property is the name in the About
dialog, shown below, but the property is currently ignored.
As tested:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
/**
* @see https://stackoverflow.com/a/22766921/230513
* @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");
JMenuItem item = new JMenuItem("Item");
fileMenu.add(item);
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Here");
}
});
menuBar.add(fileMenu);
frame.setJMenuBar(menuBar);
frame.setVisible(true);
}
});
}
}
Upvotes: 2