如何在Macintosh平台上用Java更改程序的Dock图标?我听说过使用Apple的Java库(在Mac平台上提供某种额外的支持),但我还没有找到一些实际的例子.
我已经能够像这样使用这个例子来改变运行时图标
getFrame().setIconImage(Toolkit.getDefaultToolkit().getImage(getClass()
.getClassLoader().getResource("MyProject/resources/myIcon.png")));
Run Code Online (Sandbox Code Playgroud)
但有没有办法告诉NetBeans使用myIcon.png作为可执行jar文件(MyProject/dist/MyProject.jar)图标?
当我将我移动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) 我已经尝试过 Stack 中的大量代码。出于某种原因,它只是没有为我的 JFrame 设置 ImageIcon,评论是其他没有奏效的尝试;我避免调用 super 以便我可以引用 JFrame -- GUIPhotoAlbum extendsJFrame;代码:
public GUIPhotoAlbum ()
{
super("PhotoAlbum");
ImageIcon img = new ImageIcon("Photos/albumIcon.png");
this.setIconImage(img.getImage());
/*
try{
setIconImage(ImageIO.read(new File("Photos/albumIcon.png")));
}catch(Exception e){
System.out.print("Didn't work.");
}
*/
setSize(875, 625);
this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout(5, 5));
initComponents();
initMenuBar();
initTopPanel();
add(topPanel, BorderLayout.CENTER);
initBottomPanel();
add(bottomPanel, BorderLayout.SOUTH);
addListeners();
setLocationRelativeTo(null);
setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)
编辑我正在运行这样的程序,我尝试在GUIPhotoAlbum()构造函数中设置 JFrame 的 ImageIcon ;这是司机:
public class AlbumDriver
{
public static void main (String [ ] args)
{
SwingUtilities.invokeLater
(
new Runnable()
{
@Override
public …Run Code Online (Sandbox Code Playgroud)