Java FileDialog selecting directories: Mac OSX only? - java

I read that via
System.setProperty("apple.awt.fileDialogForDirectories", "true");
users can select directories via a FileDialog, now the FileDialog evoces the native file chooser, so that is exactly what i want but in the line above it reads: apple.awt..., does this mean this option will only work on Mac OSX?
if(no) {
great
} else {
what can i do to implement this on other operating systems than?
}
Thanks for any help!
PS: I know a lot of people suggest the use of a JFileChooser, but in this case i'd very much prefer the FileDialog, except if that's impossible

It is exactly as you feared.
AWT used native libs underneath. OSX has the feature to look for directories only, windows does not.
So youre only change is to use a dialog not based on AWT, i.e. Swing or SWT.
You can define an interface with platform specifc implementations. This gives a good looking dialog on OSX and something that works on other platforms. That's what I do.

To my knowledge, FileDialog does not support (in-code) using a directory dialog on all platforms.
You're already mentioned Swing's JFileChooser, but you may want to consider SWT for your widgets instead.
SWT is Eclipse (originally IBM)'s project to create an updated Java GUI Toolkit that still uses native widgets when they are available.
The major downside of SWT is that it is not part of the standard Java distribution... and each platform has its own SWT jar file.
Incidentally, SWT has a DirectoryDialog widget.

Related

Changing the default icon in Netbeans' native deployment feature for Java apps

I know the question is very long, but in a nutshell it's just that. As you know Netbeans has a feature with the help of inno setup that allows the creation of .exe installers of Java applications. The problem is that I would like to change the default icon it has (a grey java icon) for a custom one.
I have searched a lot through both Stack and Google and I haven't found anything. The closest it got is to change it via Launch4j. The thing is if it is possible to do it within Netbeans.
Furthermore, I was wondering if there is a possibility to add several languages to the installer and some other features like the creation of a desktop icon. I guess if the option exists it would be in the same place as the change-icon... but I am completely lost regarding this issue.

Eclipse RCP & SWT Widgets & NLS

Does anyone know if its possible to do NLS to some SWT Widgets in SWT\RCP application?
remark:
With JFace components its possible if you create own equinox fragment to plugin org.eclipse.jface, (contains messages.properties), so let me say if I want to make Slovak NLS to JFace components I create messages_sk.properties in my fragment.
Does anyone knows if this could be done also to SWT which is part of plugin org.eclipse.ui ?
I am developing application which uses SWT FileDialog, which has default english buttons etc.
I want to make them other language without making my own dialog, but changing NLS..
I don't think that you have a chance to internationalize the text of the buttons of org.eclipse.swt.widgets.FileDialog.
SWT is using the system file dialog here. For me with a german win32 system the text is in german. This indicates that the button texts are also system dependent.
PS:
SWT is not part of the plugin org.eclipse.ui. FileDialog is part of the plugin org.eclipse.swt.<ws>.<os>.<arch>_<version>.jar
where:
ws - window system: gtk, win32, etc.
os - operating system: win32, linux, solaris etc.
arch - architecture: x86, x86_64
version - version id (something like 3.100.1.v4234e)
Most of the parts in org.eclipse.swt can be localized. I don't know about an option to localize FileDialog and similar "widgets", because the library calls directly some Win32 API (or similar API on other OSes) to create it. Therefore this part is highly OS dependent and wouldn't be portable if you change it somehow.
If you want to localize other parts of org.eclipse.swt, it's relatively simple. Just create a fragment (e.g. org.eclipse.swt.nls), where host would be org.eclipse.swt. Create a package org.eclipse.swt.internal.
Than copy a file SWTMessages.properties from org.eclipse.swt.<ws>.<os>.<arch>_<version>.jar/org/eclipse/swt/internal to the new package and rename it to _SWTMessages.properties.
Then you can create localized SWTMessages_<lang>.properties files (where <lang> is the language abbreviation: e.g. sk, de, fr).

Create an "accessory view" in Java Swing file dialogs

On Mac OS X, the native NSSavePanel supports an "accessory view" that can be used to specify file types and other options (using setAccessoryView:). I would like to do something similar in my Swing application as well.
I know JFileChooser supports something like this but it just doesn't look native. Is it possible to do this using AWT's FileDialog directly (which does use the native file dialog)? Maybe using Java Native Access?
No, it is not possible with FileDialog. Check out QuaQua. It's a Mac OS X Java look-and-feel that more closely matches the native UI. Its version of JFileChooser may be more to your liking.
If you're already familiar with the OS X API though, the best solution may be to just open a native dialog directly via JNI.

How to make your desktop Java app looks like Open Office or Eclipse etc.?

How to make your desktop Java app looks like Open Office or Eclipse etc ?
Installation process looks like any Windpws app. installation. There is no Java logo on the to on a app window. You run it by .exe file. How it is done? Is this jar->exe conversion?
Is there any free tool to do that?
For the native look, you can obviously go the SWT way, like Eclipse does, however it's a painful one. You could/should prefer the Swing look'n'feel, by using, as an example, the Substance Look'n'Feel.
For the installation part, you can use
InstallAnywhere
IzPack
For the exe wrapper, you can use
Launch4J
JSmooth
or others ...
However, I think that, by doing so, you're doing it wrong.
indeed, instead of the classical download/install step, which is cumbersome, you can go the Java Web Start way : user only has to click one webpage link to install application to its machine (with an update mechanism directly integrated in), an install that go as far as potentially including desktop and start menu shortcuts, and an element in the Windows install panel to remove installed software.
I tried Jar2Exe, and JSmooth, they both produce exe files from jar archives.
The question is a little unclear, but I think that what you're after is making your java app behave like a native app (stuff like running it when an icon is double-clicked, etc...). There is an excellent tutorial on this here.
Note that, for the graphic part, Eclipse uses a library called SWT, which is a set of widgets that feel and behave in a different way that Java Swing or AWT.
Anyway, if you go the normal Java (Swing) way, the Java logo on the top of an app window is setIconImage() method in JFrame components.
Riduidel already told you about .exe wrappers and installers you can use. For the installer, I also suggest you to consider Java Web Start instead of a normal Windows installer.
I think it uses LookAndFeel, I let you read: http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e){}
EDIT: I didn't read the entire question ^^' Maybe it will be useful to someone...

How to launch the default (native) application for a given file from Java?

I am displaying a list of files; i.e. xls, doc, pdf, odt etc., in my Java application (Eclipse RCP). When the user clicks on the file, I want to launch the appropriate (according to what the OS thinks) native application, just like it happens in Windows Explorer or the Finder.
And while I am here: It would be nice to also display the same icons that Finder or Explorer use for the different file types.
Is there a library or Eclipse plugin for this?
What you want is java.awt.Desktop:
Desktop.getDesktop().open( file );
I have found an API in Eclipse's SWT now that seems to do the trick:
org.eclipse.swt.program.Program "provides access to facilities for discovering operating system specific aspects of external program launching."
It has methods to find the program for a given file extension, get the program's icon, and even launch the program.
Sounds like you're after the Java Activation Framework ("JAF"). This API lets you determine what files are and what actions you can do on them. Or alternatively the Java Desktop Integration Component ("JDIC"). JDIC allows you to create and no doubt query file associations.
Both projects seem to be in a semi-abandoned state howeer (sigh). But that's par for the course for Sun these days. Only other thing I know of is some Windows specific third party library that's based on JNI called Winpack. It does a bunch of other things too.
You can get the associated icon using the FileSystemView class (Java 1.4+).

Categories