How to change default jar icon - java

First I have read all questions about this subject, so this is not a repeated question.
What I want to ask about, how an application written in Java (such as eclipse) uses an icon instead of the default jar icons.
I don't care about compatibility, I always can make 2 different versions of my program to Windows and Linux.
How to make it in Linux and Windows.
Thanks very much.

In the case of programs like eclipse, which are written in java and have a specific icon in Windows (or Linux or Mac for that matter), they actually have an OS specific executable file, e.g. eclipse.exe for windows, that initialises the java program.
It is this executable that contains the application icon, not the Java program. If you want to do the same, you'll need to create the executable 'front door', as it were, and give it an icon.
If it's just for your own personal aesthetics, just create a short cut to the jar file and change the icon of the shortcut.

To set an image for MAC, you can use com.apple.eawt.Application. try this:
Image img = new ImageIcon("abc.png").getImage(); // your desired image
Application app = Application.getApplication();
app.setDockIconImage(img);
However, this will not build on Windows or Linux by default. If you'd like it to, (Maven) add the following dependency to your POM:
<dependency>
<groupId>com.yuvimasory</groupId>
<artifactId>orange-extensions</artifactId>
<version>1.3.0</version>
</dependency>
Or, if you don't use Maven, you can download the JAR from http://central.maven.org/maven2/com/yuvimasory/orange-extensions/1.3.0/orange-extensions-1.3.0.jar

If the application is launched using Java Web Start, an application icon can be specified for use in desktop shortcuts and menu items.
Note that this icon is not attached directly to the Jar, but since the end user never sees or has to deal with a Jar, that should not be a problem.

I use NetBeans, so if you aren't using that, I don't quite know. But, when you select the window, there is an option in the properties window for an icon file. When you build the .jar, that icon should be built in with the program.

If you're talking about the actual application icon in, say, Windows, you can't change it (programmatically). That's determined by the OS. Although you can change it in your OS in Folder Options.
You can, however, set the window (read: JFrame) icon image using setIconImage().

Related

How to add "About" tab on Mac

On a Mac, there is a button on the screen menu bar that is the name of an application. For example, for terminal, there is a button at the top of the screen labeled Terminal. When you click it, there is a options that says About Terminal. When this is clicked, it shows information about the application. Here is a picture:
How can I add this to my application in Java? When I do this now, this is what shows up:
As you can see, it shows the Java version etc. Is there a way to change this into a more professional format?
If your Window extends JFrame, just use the setIconImage or setIconImages method to set your icon.
From the corresponding JavaDoc:
Sets the image to be displayed as the icon for this window.
The other information is read from the executable metadata. If you run your app using Java directly, you can't change it. For my applications, I generate an executable file using Install4J, where the installer adds the metadata to the generated executable.
Thanks, I've solved the problem. It was a simple mistake, when I packaged it together using a packager it worked fine. Thanks for all your help!

How to make a .plist for a mac applications

I'm trying to turn a java program into a mac .app file, or more accurately, a native mac application. This requires a .plist file (see here) but I can't seem to find anywhere that works in telling me how to make one. I set up the directories as they specified, and my application debugs properly. Its just every time I try to open the application, it immediately shuts down. Does anyone know how to make a (minimalist even, for now) working plist file?
Right click on your project and select Export. Assuming you on using a Mac, there will be an option to output an application bundle.
Once you have created the app bundle (which itself is just a directory), go here to find the Info.plist file:
MyApp.app/Contents/Info.plist
From there you can edit the plist, if you need to.

How to launch draw9patch and is it absolutely necessary to rescale pictures?

I read on another forum that to launch draw9pad from your console, you have to do java -jar draw9patch.jar from the command prompt once youre in sdk. I did that but i still cannot launch the file. Is this tool absolutely necessary for your pictures to scale on different screens? I know that eclipse has these drawable folders that scale your pictures to different dpis or is that not what they do?
Console output: http://imgur.com/YdGLHXr
File skd/tools :http://imgur.com/vOU647L
To answer the first question for a Mac OS or Linux user, simply type sh draw9patch to launch the editor. CommonsWare already answered the second question.
I read on another forum that to launch draw9pad from your console, you have to do java -jar draw9patch.jar from the command prompt once youre in sdk
Please use the draw9patch batch file or shell script found in the tools/ directory of your SDK installation.
I did that but i still cannot launch the file
First, that is because you did not type it in correctly, as you did not include the .jar extension.
Second, that JAR file is not in that directory. You can tell that by looking at the directory contents.
Instructions for running draw9patch can be found in the Android documentation.
Is this tool absolutely necessary for your pictures to scale on different screens?
Quoting the documentation:
A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View in which you have placed it as the background.
Scaling for different screens is not really the role of a nine-patch PNG file. Scaling for different content is. A nine-patch is used as the background for widgets like Button, EditText, and the like.

How do I create a Windows-like clickable shortcut for Mac OSX?

I am helping a colleague set up some GUI programming tools I have written in Java.
I need to create a clickable icon to run the application which sets the current directory and then invokes the JVM, passing parameters to the program. Also nice would be to be able to use the PNG icon image I created for the program.
I suspect I need to create a script and somehow add that to the launcher strip that's across the bottom of the screen. Once off manual creation is all I need, not programmatic.
What's the right way to do this?
Use the Jar Bundler! With the Jar Bunder you can specify the Main class, any arguments, additional files and resources to the classpath, VM options and many more.
Have a look at this tutorial. There is also an Ant task available (not tried myself yet). If you have installed Xcode, it is located under /Developer/Applications/Utilities/Jar Bundler.app. The Jar Bundler itself is not public downloadable (except the ant task). I'm not sure, if the Jar Bundler is part of the standard Mac OS distribution. Start the terminal and have a look at /usr/share/java/Tools/Jar Bundler.app. You need an apple developer account to get Xcode if it is not present.
if you can do jnlp it will work in both mac and pc world
In OS X the closest thing to a shortcut that I am aware of is an alias. I'm not aware of any Java APIs for creating an alias directly, however you might consider invoking the ln -s command which creates a symbolic link, which is equivilant to an alias.
I can't confirm it works caus I'm on a PC but try
ln -s "/path to/your/app -arg1 -arg2" "alias name"
The OS X documentatiopn for the command is here

Java application does not work properly outside IDE's directory

When I run it with NetBeans it's all OK. When I copy dist directory contents and run .jar, some stuff gets buggy. Most important, JTable editing gets messy, some fields lose focus only when you hit ESC (if you did hit ENTER before, changes are accepted, otherwise they are not, but you need ESC in both cases) and similar weird stuff. I got a feeling that I'm missing something obvious...
P.S. files are compiled automatically on save (NetBeans feature) if that matters.
Edit: when I just go to dist dir and run .jar, it works too. Problems begin when I copy dist dir out of NetBeans projects dir... can it be that some dependencies get broken or something?
Edit 2 (reply):
This problem was happening in my computer (Ubuntu 9.04), in my Windows XP inside Virtual Box and in another (real) computer with Windows XP. When I run it from console with java /path/to/main.jar it throws mainClassNot found exception and does not launch at all. When I run it with java -jar /path/to/main.jar, it works of sorts, but when it comes to said situations, it throws java.lang.NumberFormatException: null.
The only place I use NumberFormat (on table update) is:
DecimalFormat parser = new DecimalFormat("0.00");
And, possibly, this:
currencyFormatter = NumberFormat.getCurrencyInstance( Locale.getDefault() );
Where default locale is set to
Locale.setDefault(new Locale("lt", "LT"));
Java version is 1.6.0_18, both JDK used by NetBeans and JVM in said machines.
In NetBeans go to your project's properties (File > Project Properties). Go to the Libraries tab. Click Manage Platforms and see the value for the Platform Folder.
From a console, run <platform folder>\java -version.
Now try it again without the full path; just java -version.
I would expect these are returning different values.
The path used by the IDE comes from the platform definition which, by default, is created when NB is installed and never updated. The path used in the console is from the windows PATH environment variable. This is updated whenever Java is installed and will, over time, diverge from the path used by the IDE.
A good rule of thumb is when Java prompts that an update is available it's time to add a new Java Platform in NetBeans.
I usually keep several platforms around. At a minimum:
latest versions of 1.4.2, 1.5.0, 1.6.0, and an old version of 1.6.0 (currently u4, the version we recommended in our first product release).
Have you tried something as mundane as making a clean build to make sure all new changes and resources are copied to the dist library?
Interesting... JAR's are stored in ZIP format, so you could try comparing the JAR that you've compiled with Netbean's JAR (if you can find it) to see exactly what is different.
Different JRE versions? That would be my guess, looking at your symptoms.
There are different ways to do this, but you could get the complete details of both the processes (one launched by NetBeans and one without) using jconsole (jdk_dir/bin/jconsole.exe). This would give you the JRE, loaded jars, etc that you could then compare...
HTH...

Categories