I have one Java program that browse the path of our local file system, for this we have used JFileChooser. If folder name is in simple English works fine on Windows, Mac OS X and Linux. But If I create folder named special character like - ábc Eóz then it shows that special character name on Windows and Linux only, but on OS X I am unable to see those special character folders. It ignore them from list of folders.
My program is built on java 7 update 21.
Mac OS X version - 10.8.2
How can I solve this issue?
Thanks
UPDATE : We are creating an app for Mac using JavaFX packaging. When we are running app.jar directly, it showing me path containing special char. But if we are trying to launch application using app then it skipped that special char folders.
I just tried a sample:
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
public class Trial {
public static void main(String... args) {
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel();
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(frame);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}
}
}
on a OS X 10.9.1 running JDK 1.7.0_51. I created the following folders hierarchy: ~/Documents/Joyeux Naufragés/ábc Eóz: .
In order to address the problem you described I installed also the JDK you pointed out, JDK_1.7.0_25 and I managed to reproduce the same issue, here is the snapshot for the same window running u25
As one can see the folders containing special characters don't show. So I checked also with
JDK 1.7.0_40 and surprise - it works. After that I went over the bugs fixed in the given version, I found out that several bugs related mac os x where fixed in this release. Among which a couple (7024118, 7032018, 7032436, 7161437) refer to issues in JFileChooser. There are other issues related to mac (45 in total) out of which one refers to FileDialog. Unfortunately the links to the bug descriptions don't work, so I cannot post more info on the subject, but the solution for your issue is definitely to update to at least version 1.7.0_40 even if I suppose the best would be to update to the latest (1.7.0_51).
Good luck with your work. I hope this helps you.
As we are building app using JavaFX packaging and we have our customized Info.plist kept inside ..buildscript_path/package/macosx/ folder at local path.
The problem of ignoring special characters get resolved by adding following keys to Info.plist.
<key>LSEnvironment</key>
<dict>
<key>LANG</key>
<string>en_US.UTF-8</string>
</dict>
On adding this line of code into info.plist, then building app solved my issue.
Thanks
Related
How can I change the Dock Icon of a program, in Java, on the Macintosh platform? I have heard about using Apple's Java library (that provides some sort of extra support on the Mac platform), but I have yet to find some actual examples.
While I'm not sure how to change it at runtime, you can set at the command line your Dock icon using the -Xdock:icon option, like:
>java -Xdock:icon=/path/myIcon.png myApp
This article has lots of useful little info about bringing java apps to Mac, and you may be interested looking at the utilities and tools for Mac listed here, as well as deployment options listed here (the last link is especially useful if you want to go down the Java Webstart route).
Apple eAWT provides the Application class that allows to change the dock icon of an application.
import com.apple.eawt.Application;
...
Application application = Application.getApplication();
Image image = Toolkit.getDefaultToolkit().getImage("icon.png");
application.setDockIconImage(image);
Solution for Java 9 and later
In JDK 9, internal APIs such as those in the Mac OS X com.apple.eawt package will no longer be accessible.
see: http://openjdk.java.net/jeps/272
package main;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Image;
import java.awt.Taskbar;
import java.awt.Toolkit;
import java.net.URL;
/**
* author: flohall
* date: 2019-07-07
*/
public final class Main {
public static void main (String[] args){
final JFrame jFrame = new JFrame();
//loading an image from a file
final Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
final URL imageResource = Main.class.getClassLoader().getResource("resources/images/icon.gif");
final Image image = defaultToolkit.getImage(imageResource);
//this is new since JDK 9
final Taskbar taskbar = Taskbar.getTaskbar();
try {
//set icon for mac os (and other systems which do support this method)
taskbar.setIconImage(image);
} catch (final UnsupportedOperationException e) {
System.out.println("The os does not support: 'taskbar.setIconImage'");
} catch (final SecurityException e) {
System.out.println("There was a security exception for: 'taskbar.setIconImage'");
}
//set icon for windows os (and other systems which do support this method)
jFrame.setIconImage(image);
//adding something to the window so it does show up
jFrame.getContentPane().add(new JLabel("Hello World"));
//some default JFrame things
jFrame.setDefaultCloseOperation(jFrame.EXIT_ON_CLOSE);
jFrame.pack();
jFrame.setVisible(true);
}
}
This code can be used as is. Just change the path of the image.
This new implemented way (in JDK 9+) of setting the icon for mac os dock is better then before because you won't run into any problem when building your application. Also there is no problem to use this code on a windows computer. Reflection which is not recommended since Java 9 is not needed either.
If your using Eclipse, you can export a project as a Mac OS X Application Bundle and specify an .icns file to use as an icon.
In Eclipse, go to File>Export and choose the 'Mac OS X Application Bundle' option inside the 'Other' directory.
Click the next button.
Then you'll be presented with the 'Application Bundle Export Menu'.
The last option on this menu is 'Icon'. This is where you specify the .icns file to use as the dock icon.
Picture of the 2 Eclipse Export Menus
As far as creating the .icns file is concerned, you can use Apple's Icon Composer to create a .icns file from an image file. Here is a good tutorial on making mac icons.
For Microsoft Windows
setIconImage(new ImageIcon("Football.png").getImage());
For Mac OS X
import com.apple.eawt.Application;
Application.getApplication().setDockIconImage(new ImageIcon("Football.png").getImage());
If you have XCode installed, you can use JarBundler to create a Mac App using a Jar file. If you don't have XCode, you can use this JarBundler:
http://sourceforge.net/projects/jarbundler/
During the creation of the bundler, you can choose an icon in the .icns extension. That will be your Dock Icon.
hi i'm trying to use java 3d in both command prompt and in netbeans. I have a win8 64 bit computor. I installed j3d-1_5_2-windows-amd64.exe. and it got installed inside java folder in a folder called Java3D. then I added an environmental variable as CLASSPATH and the values are C:\Program Files\Java\Java3D\1.5.2\lib\ext\j3dcore.jar;C:\Program Files\Java\Java3D\1.5.2\lib\ext\j3dutils.jar;C:\Program Files\Java\Java3D\1.5.2\lib\ext\vecmath.jar.
my file get compilled without errors when I try to runit from command prompt using the command java -cp . Hello3d it gives a calss not found error for javax/media/j3d/Node. and when i try to import 3d libraries from netbeans it gives an error on j3d after import com.sun. the following is the class I compiled from command prompt. please tell me what i'm doing wrong. thanx in advance
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.BranchGroup;
public class Hello3d {
public Hello3d()
{
SimpleUniverse universe = new SimpleUniverse();
BranchGroup group = new BranchGroup();
group.addChild(new ColorCube(0.3));
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(group);
}
public static void main( String[] args ) {
new Hello3d();
}
} // end of class Hello3d
You use an obsolete version (1.5.2) of Java3D, this version is no longer maintained since a few years. Please uninstall it and install the latest version (1.6.0). Follow my instructions here.
Your code runs perfectly in my eclipse environment using java3d version 1.5.2.
It shows an ugly cube seen from one side only, red faced.
I guess you need to set the path to the native libraries that java3d needs.
Regrettably, I don't know how to do this on windows (R).
Regrettably I have not enough reputation to put this into a comment rather than an answer.
If anyone with enough reputation cares, please turn this answer into a comment.
So i have come across a problem with installing my java application to startup on all Operating Systems.
Firstly I know this is possible on Windows by adding a new key to registry (I think).
I believe the command: 'reg add' works on windows.
I'm not 100% sure about Mac but i believe you can use a service wrapper?
And for Linux I have no clue.
Basically i want my application to be installed to startup when a user ticks a box, no matter which operating system it is run on.
Just some clarification on these and if possible an example for each would really assist me.
Any help with this is greatly appreciated.
Thanks.
Add a .desktop file to one of the following directories:
$XDG_CONFIG_DIRS/autostart/ (/etc/xdg/autostart/ by default) for all users
$XDG_CONFIG_HOME/autostart/ (~/.config/autostart/ by default) for a particular user
See the FreeDesktop.org Desktop Application Autostart Specification for details.
So for example,
PrintWriter out = new PrintWriter(new FileWriter(
System.getProperty("user.home")+"/.config/autostart/myapp.desktop"));
out.println("[Desktop Entry]");
out.println("Name=myapp");
out.println("Comment=Autostart entry for myapp");
out.println("Exec=" + installPath + "/bin/myapp_wrapper.sh");
out.println("Icon=" + installPath + "/myapp_icon.png");
out.flush();
out.close();
I am trying to get a hello world SWT application going:
public static void main(String args[]) throws IOException{
Display display = new Display ();
Shell shell = new Shell(display);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
But I keep getting the following exception. I have the macosx version of org.eclipse.swt.carbon being used with eclipse/maven. Has anyone seen this before?
Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-carbon-3346 or swt-carbon in swt.library.path, java.library.path or the jar file
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:219)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:151)
at org.eclipse.swt.internal.C.<clinit>(C.java:21)
at org.eclipse.swt.widgets.Display.createDisplay(Display.java:943)
at org.eclipse.swt.widgets.Display.create(Display.java:937)
at org.eclipse.swt.graphics.Device.<init>(Device.java:119)
at org.eclipse.swt.widgets.Display.<init>(Display.java:749)
at org.eclipse.swt.widgets.Display.<init>(Display.java:740)
at com.wuntee.aat.command.adb.LogCat.main(LogCat.java:30)
SWT is implemented using native UI libraries - in this case, the Mac Carbon libraries - and requires some JNI code to marshal the SWT calls to the native Carbon calls. Loading JNI libraries is a little bit different than normal classloading (the dynamic libraries must first be loaded with System#loadLibrary).
First, if you're on a 64 bit machine, make sure that you're passing the -d32 argument to the JRE. (ie, java -d32 MyTestClass). The Carbon SWT libraries are 32 bit only and will not load on a 64 bit runtime.
By default, SWT tries to load the .jnilib dynamic libraries from a JAR file in your classpath - the library libswt-carbon-3346.jnilib should be in your org.eclipse.swt.carbon.macosx... JAR. SWT will try to unzip this jnilib from your JAR into a temporary location and load that.
If it can't do this for whatever reason (java.io.tmpdir isn't writable, for example) then this will fail. To work around this, you should extract libswt-carbon-3346.jnilib from the org.eclipse.swt.carbon.macosx JAR and follow the instructions that the exception provided. (For example, set swt.library.path to the location of that jnilib.)
Unrelated to your actual question: you're using SWT 3.3. A lot of changes have been made since then, including the (likely preferable) Cocoa support. Upgrading to the newest SWT libraries in the newest Eclipse may be very helpful.
in one of my questions ,somebody said that I have to make sure that I'm not using compiler 1.6 and 1.5 runtime when i want to execute or debug my program,but I don't know how can i check compiler and runtime in NetBeans ,I am beginner with NetBeans.
my question was:
**I debug my project and the result was :
debug: Have no FileObject for C:\Program Files\Java\jdk1.6.0_02\jre\lib\sunrsasign.jar
Have no FileObject for C:\Program Files\Java\jdk1.6.0_02\jre\classes**
what should i do?
and he answers : you have to make sure that you are not using compiler 1.6 and 1.5 runtime when you want to execute or debug your program
Here's what I use to find out everything about my building environment (never felt too warm with Eclipse):
import static java.lang.System.out;
public class Zeug {
static String[] opts = new String[] { "java.version", "java.vendor",
"java.vendor.url", "java.home", "java.vm.specification.version",
"java.vm.specification.vendor", "java.vm.specification.name",
"java.vm.version", "java.vm.vendor", "java.vm.name",
"java.specification.version", "java.specification.vendor",
"java.specification.name", "java.class.version", "java.class.path",
"java.library.path", "java.io.tmpdir", "java.compiler",
"java.ext.dirs", "os.name", "os.arch", "os.version",
"file.separator", "path.separator", "line.separator", "user.name",
"user.home", "user.dir" };
public static void main(String[] args) {
for(String o : opts) {
out.println(o + ": " + System.getProperty(o));
}
}
}
Go to Tools-->Java Platform and you should see the JDK you are using listed. I am using java-6-sun-1.6.0.16 which does indeed have the jar file you need.
Download the latest JDK from Sun. Go to Tools-->Java Platform and click Add Platform. Navigate to where you installed the latest JDK, name it something meaningful like JDK 1.6.0.16 or whatever and click Finish. Right click on the top level of your project and click Properties. At the top of the popup window change the Java Platform to the one you just added and click ok. At that point, you should not experience your current problem when you compile.
JDK Download Link
You can set the Java version to be used in the project properties (right click on the project).
Edit: after seeing your specific error message: this seems to be a deeper problem. For some reason Netbeans is looking for a file sunrsasign.jar, which is not normally part of the JDK. Looking for the filename on Google indicates that it's part of a cryptography extension, but that seems to have been integrated into the JDK by now. So the JAR is not needed anymore.
I don't know whether it's Netbeans (are you using the most recent version?) or your application that is mistakenly looking for a JAR that has been integrated into the JDK library itselt.