I would like to implement Mac OS X native printing in my Java desktop application.
That is, this print dialog when the user chooses to print:
which then expands to a dialog such as this:
As I understand it, native Mac OS X applications can customise the 2nd dialog by adding an option in the lower drop-down ("TextEdit" in the screenshot) which when selected displays options specific to the application.
How is the best way to go about achieving this in my Java application? I presume I will need to write some Objective C to do what I need, then use JNA/JNI to call it? Are they are pre-existing libraries that can help me?
You are correct in think you need to go down the JNI route.
Apple has a tech note on developing JNI routines here: http://developer.apple.com/library/mac/#technotes/tn2147/_index.html
Related
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.
I'm wondering if anyone has any experience using JNA to call windows sendMessage API from a java web application running in a browser to change the focus from the browser to another program that is already running on the computer.
I'm building out a Parts catalog that once the user has chosen the parts they want to sell to the customer, I need to automatically open the Point of Sale system so that the employee can tender the transaction. They want this to happen on some event in the parts catalog, not just an ALT-Tab or something similar. I believe the registers run some sort of kiosk version of XP and the browser (Probably going to be Firefox 5), so some of the functionality, like the task bar and start menu, etc. are not there. Maybe JNA and the windows API is the wrong way completely. Any help or direction would be greatly appreciated!
A straightforward method would be to enumerate the extant windows until you find the one you're looking for, and then invoke the appropriate win32 method to activate/focus that window directly.
I was trying to define a custom name as explained in this question, but there is no application package in my com.apple.mrj. Is this a known issue? how can I workaround this?
Thanks in advance.
The easiest way to show a custom name on Mac OS X is to use the -Xdock option of java.
java -Xdock:name=CustomName ...
You can see more details using the command java -X. You might also look at OSXAdapter, which puts "preferences, about, and quit functionality into handlers for the Mac OS X application menu."
I know the following things, and was wondering if they can be combined to make Java use jump-lists in Windows:
Windows displays Jump-Lists for supporting programs when a taskbar icon is right-clicked
C++, C#, F#, and VB support this natively (as shown here)
Java can import native capabilities using the JNA (as shown here)
Anybody have experience they can lend to help me create a jump-list for a Java app?
The J7Goodies library won't work, as it no longer exists.
The word "natively" is overstating the case a bit. WPF provides jump list support. That's not the same as C# providing it. (For Windows Forms people there's the Code Pack which is a set of managed wrappers.) And MFC provides jump list support which is also not the same as C++ providing it. Anyway, there are two things going on here. One is adding files you opened recently to that jumplist, which under some circumstances you can get for free. The other is adding arbitrary files (typically starting point templates etc) to the jumplist.
To add a file to the recent/frequent list, you call SHAddToRecentDocs, though you may not have to if, for example, you use the Common File Dialog control to open files, and/or the user double-clicks files to launch your app and open them (you have the file type registered.) Lots of folks suggest calling it anyway to be on the safe side. To add any old thing to the jumplist see http://msdn.microsoft.com/en-us/library/dd378402(v=VS.85).aspx.
How to call those from Java, I forget, but I hope they get you started.
There is a Java library providing the new Windows 7 features for Java. It's called J7Goodies by Strix Code. You can create your own jump lists with it.
I have a Java program using AWT which I would like to run on a headless system. The display for the program does nothing other than display stats. When the program finishes, it exits. There is no user interaction on the display. The program creates an output file which I use in my build system.
Is there a way to get the Java program to run without an X11 display configured? Can I force Java to run the program without trying to display anything? I do not have access to the source code (it is just .jar file), so I can't make modifications to the source.
Any thoughts on how I could get this to work?
The underlying question here is how to run Java applications without an X server; providing a "fake" X server is only one option. In Java 1.4 and up, you can do the following:
java -Djava.awt.headless=true
This allows applications which use AWT to run on headless systems even without an X server.
Xvfb can do what you ask for. I've not used it myself, but here is a link to wikipedia: http://en.wikipedia.org/wiki/Xvfb
You can use a vncserver.
vncserver :1001
export DISPLAY=localhost:1001
java..
The added advantages is that you can actually view the gui
using vncserver 'just in case'
Could also run Xvnc in a low resolution and color depth.
As mentioned by Charles Duffy the traditional method is to tell Java to go headless.
Note that you can always mount the jar in Eclipse and use jad+jadclipse to see what it actually does, and perhaps even override a class if you need to by putting another class-file in "front" of it in the classpath.
A facility that might be relevant if the program uses Java2D is that newer Java versions use optimizations in the X11 server to render faster. This alone might be a reason to devote an X11 server attached to a high performance graphics card to your graphics processing.
I've used with great success in the past the PJA libraries, they don't seem to be maintained anymore, but then again, just just want to run...
I was able to get headless mode in OpenJFX with the command line arguments
-Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw