Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the default application icon image in Java swing on OS X

I'm trying to set the icon image for a Jar file:

setIconImage(new ImageIcon(getClass().getResource("logo.png")).getImage());

When running in Mac OS X 10.7.4 I get the following error:

Jun 28 15:21:40 (my dhcp) java[73383] <Error>: CGContextGetCTM: invalid context 0x0
Jun 28 15:21:40 (my dhcp) java[73383] <Error>: CGContextSetBaseCTM: invalid context 0x0
Jun 28 15:21:40 (my dhcp) java[73383] <Error>: CGContextGetCTM: invalid context 0x0
Jun 28 15:21:40 (my dhcp) java[73383] <Error>: CGContextSetBaseCTM: invalid context 0x0
Jun 28 15:21:40 (my dhcp) java[73383] <Error>: CGContextGetCTM: invalid context 0x0
Jun 28 15:21:40 (my dhcp) java[73383] <Error>: CGContextSetBaseCTM: invalid context 0x0
like image 436
rhombidodecahedron Avatar asked Jun 28 '12 22:06

rhombidodecahedron


People also ask

How do I change the Java Swing app icon?

How to change TitleBar icon in Java AWT and Swing. The setIconImage() method of Frame class is used to change the icon of Frame or Window. It changes the icon which is displayed at the left side of Frame or Window. The Toolkit class is used to get instance of Image class in AWT and Swing.

What image types are supported in a Swing GUI?

Swing provides a particularly useful implementation of the Icon interface: ImageIcon , which paints an icon from a GIF, JPEG, or PNG image.

How will you assign the string and icon both to the JButton?

To add icon to a button, use the Icon class, which will allow you to add an image to the button. Icon icon = new ImageIcon("E:\editicon. PNG"); JButton button7 = new JButton(icon); Above, we have set icon for button 7.

What is Java Control Panel on mac?

The Control Panel allows you to find information about Java version and configure various settings to help you efficiently run Java on your Mac.


1 Answers

java -Xdock:icon=/path/myIcon.png myApp

like image 198
Alex Teixeira Avatar answered Oct 05 '22 23:10

Alex Teixeira