4

I tried to set the application name and icon for the Mac OS X dock in my Java program. I used the following code:

public static void main(String[] args)
{
    Application.getApplication().setDockIconImage(icon); // Dock icon
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Alfabet"); // Program name

    new UpdateChecker(); // Check for an update
    new Alfabet(); // Start the program
}

The object 'icon' is an java.awt.Image. The class Alfabet creates the main JFrame of the program. The icon shows up correctly, but the application name doesn't, it still displays the name of the main class of the program. What am I doing wrong? Thank you.

jobukkit
  • 2,490
  • 8
  • 26
  • 41

1 Answers1

3

It's not clear where things are going awry, but there's a complete working example here for reference.

Alternatively , try setting the name from the command line:

java -Xdock:name=Alfabet

See also Initial Threads.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Can I do that command line thing from within the code? I would like to keep everything in a easy to use double-click-to-start multiplatform jar file. – jobukkit Aug 11 '12 at 14:38
  • Yes, just do it _before_ `invokeLater()`, as shown in the example. – trashgod Aug 11 '12 at 14:58
  • Ok, how do I enter a command line from within the code? Sorry, I'm a beginner... And thank you for helping me :) – jobukkit Aug 11 '12 at 15:56
  • You should choose one way or the other. What happens when you run the [example](http://stackoverflow.com/a/8956715/230513) cited? – trashgod Aug 11 '12 at 18:14
  • Hey, your example code works! I tried `public static void main(String[] args) { System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Alfabet"); Application.getApplication().setDockIconImage(icon); EventQueue.invokeLater(new Runnable() { @Override public void run() { new UpdateChecker(); new Alfabet(); } }); }` now because your example also used `invokeLater()` but it still doesn't work :( Do you know what I'm doing wrong? – jobukkit Aug 11 '12 at 20:01
  • You may need to set `apple.laf.useScreenMenuBar`, too. – trashgod Aug 11 '12 at 21:34
  • I'm nonplussed. What happens if you omit `new UpdateChecker()`? – trashgod Aug 12 '12 at 09:44
  • It still doesn't work... I even tried to omit both `new Alfabet()` and `new UpdateChecker` and replaced with `System.out.println("some text");`to see the problem was somewhere in Alfabet.class or in UpdateChecker.class, but the name still didn't show up. – jobukkit Aug 12 '12 at 16:45
  • And yet my example _does_ work? Sorry, I don;t have a lion on which to test. – trashgod Aug 12 '12 at 16:53
  • Yes, your example does work! I don't now what's going wrong then :( – jobukkit Aug 12 '12 at 18:25
  • Try starting from mine and add bits of yours to see what breaks. Also clean and rebuild your project. – trashgod Aug 13 '12 at 01:20
  • 1
    I got it working now! The problem was that my main() was at the bottom of Alfabet.class. Now that I moved main() to a seperate AlfabetStart.class, it works. Thank you for helping me! – jobukkit Aug 13 '12 at 09:59