Java OS X Dock Menu - java

Is it possible to add items to the applications dock menu?
EDIT: I think i miss phrased the question, i am not looking for a way to add an icon to the dock. what i am looking for is, when you right click on the itunes icon you get itunes control on the menu (play pause etc) i was wondering how can i add custom items to that menu.

Look into the com.apple.eawt package. Specifically, when you initialize your app, do something like the following:
if (System.getProperty("os.name").startsWith("Mac OS X")) {
// only do this setup if we know this is a Mac
com.apple.eawt.Application macApp = com.apple.eawt.Application.getApplication();
java.awt.PopupMenu menu = new java.awt.PopupMenu();
// create your java.awt.MenuItem objects here
// add to menu via java.awt.Menu#add(java.awt.MenuItem)
macApp.setDockMenu(menu);
}
If you are distributing this as a cross-platform application, Apple provides an Apple Java Extensions jar with stubs for the com.apple.eawt package, so the code will compile with non-Apple JDKs.

Yes (providing I understand the question).
If your just trying to customize the Java Icon in the Dock see ...
http://developer.apple.com/documentation/Java/Conceptual/Java14Development/03-JavaDeployment/JavaDeployment.html#//apple_ref/doc/uid/TP40001885-208447-TPXREF120
Point two under OSX Application Bundles section
"If you add an appropriate icon, it shows the application icon in the Dock, clearly identifying your application. (Otherwise, a default Java coffee cup icon appears in the Dock.)"
There is an example app (Java) for handling drag and drop events for your dock icon as well located here :
http://www.devdaily.com/blog/post/jfc-swing/java-handle-drag-drop-events-mac-osx-dock-application-icon
If you want you application to automatically add it's icon during installation to the dock (possibly what you mean) you should know that there is no "official apple" way to do this as it's BAD design on OS X to force your icons into a users dock, and typically frowned upon. All MAC users i know will instantly remove your application as a result of such behavior.
That said however, you can review the system administration guides on Apple's site to see how it can be done programatically.

Related

Is it possible to use a mouse listener on a windows tablet?

I've been asked to write an app for a kid's treasure hunt TV show. It's a very simple app, all that happens is this: the app displays a picture of a treasure chest. When the child taps the treasure chest, it changes to one of a few possible pictures of an ingredient (like a fish or chicken or something), then on the second tap it shows a recipe for a meal and the kid has to make it. They need it to be made for Windows tablets though, and since I don't have one I have no way of testing my apps.
My question is this: I made it on Java (using awt and the paintComponent method and a mouse listener to change on click) and since the tablets run windows, can I make it an executable and put it straight on the tablet and would the touch behave like a mouse? Or would my code need to be completely different if I'm incorporating touch? If my route is completely wrong, then which languages should I use to write code for windows tablets?
Depends on te tablet. Here is the quote from oracle's web page:
Is the Java download available for the Windows Surface tablet?
No, since the Windows Surface tablet does not support the Java plug-in, Java cannot be installed on the Surface tablet. Only the apps available in the Windows Store can be installed on Windows Surface that uses Windows RT or Windows RT 8.1 operating system.
And the link.
If the tablet supports java it should work just fine including click events.
You can also pack jar to exe using Launch4j which is free or you can make windows like installer using tool called Advanced Installer but its not free.
Hope i helped.

Two icons on taskbar when running java application

Hey so I have a Java application where I use a JFrame as the main window. My problem is when I pin the executable to the taskbar and then run the executable a second icon is placed on the taskbar instead of a "glow" being placed on top of the icon that is already pinned. In other words, two icons on the taskbar when I pin and run the executable. Is there any coding solution to this problem?
Please even let me know if you think there is no way or if you have come across this before.
There could be multiple reasons for this:
Do you have more than one JFrame getting a task-bar icon? Referencing this question: how to restrict more than one java application icon on taskbar?
It could be that the pinned version is not the same as the one that actually runs, i.e. trying pinning the second icon that appears, then using that icon in the future.
You might need a setting in your configuration if you have any, Eclipse (the IDE) seems to suffer from this problem and requires the JVM tp be specified in it's ini file, referencing: How to make Eclipse behave well in the Windows 7 taskbar?
Last Resort. The IsHostApp setting in the registry can change the way java behaves on the task bar, you would still have two icons, they would just stack:
https://superuser.com/questions/465002/how-do-i-combine-multiple-java-buttons-into-a-pile-on-the-taskbar/465248#465248

How can I display multiple dock items for jFrames within one Java application?

I have a modular Java application: a single jar launches a 'control panel', from which the user can open several modules. Each module uses its own jFrame. (A discussion of whether this is a good or bad practice can be found here - in my case the modules all talk to one another but perform different functions).
Running on Windows, each module (jFrame) gets its own icon on the taskbar, and is selectable via ALT-tab. On OS X I only get one dock icon and one icon in the Application Switcher (CMD-tab). This makes it quite awkward to switch between modules, several of which will be open at any one time.
How can I put each module (jFrame) in the OS X dock and Application Switcher separately?
Iterestingly, if I iconise one of the jFrames, it does appear in the dock, in the right-hand area by the Trash.
I am testing this using Java 7 on OS X 10.10 (Yosemite). I have made a cheat's .app which launches the jar via a shell script, in order to provide cmd-line arguments (Xdock:name etc) and icons - so I do have an info.plist file.
You can't. The OS X user interface just doesn't work that way.
Iterestingly, if I iconise one of the jFrames, it does appear in the
dock, in the right-hand area by the Trash.
This is user-configurable. See Preferences > Dock > Minimize windows into application dock.
Rather than fight against the normal OS behavior, come up with your own "module switcher" feature, perhaps making it part of your control panel. You will find that application switching and dock icon behavior differs a lot across operating systems. Trying to make OS X behave like Windows, or vice-versa, outside the bounds of your application will be a big headache.
That said, if you don't want to heed the above advice, the only way I can think of to do what you want is to create dummy applications, that don't display any windows, but that do show up in the dock. The dummy applications can be started by your main application. When a dummy application is clicked, it can then signal your main application (perhaps listening on a local open port) to make one of the modules active. This would give the illusion that each module had its own place in the dock. This would probably work with the Alt-Tab switcher as well.

Set an icon similar to mac when minimized it to dock

Set an icon for a JFrame when it is minimized to the dock like other mac application.
Please help..
An e.g. of what Mikle was referring to:
Now moved to: Sizes of frame icons used in Swing.
Use the jar bundler that is available with Mac os to create an App. Set the icon of the app using jar bundler and dont set any icons for your jframe.
Window class has method setIconImages which requires java.util.List<? extends Image> as an argument. You will have to pass a list of images with different sizes so that OS can choose one from that list for each specific situation - would it be minimized icon, icon for dock/toolbar, icon for window or icon for any other system-specific UI element.
I usually pass a lot of images for my own application in different sizes:
16x16, 24x24, 32x32, 48x48, 64x64, 128x128, 256x256, 512x512
The large ones are usually used by large toolbars or by folder view to display icons for files associated with your application. Also usually 16x16 icon is used as window (frame/dialog) icon. Other icons can be used in a lot of different situations which depends on what OS you have (Windows, Mac OS e.t.c).
You're really talking about two things.
The icon of the application in the dock, in Finder, etc.
appbundler or even simply hand-creating the bundle is the solution to that, as already
mentioned.
The icon of the application when minimised to the dock
When you minimise the application it becomes a separate dock entry which does not
necessarily look like the application one.
The Window has setIconImages - if you set this method, the application will become
that icon when minimised which will not look native. So you should check if you're
running on OSX before calling that method and avoid calling it.
By leaving out the call, you get the default behaviour where the minimised icon will
be a miniature copy of what the window itself looks like, which is what we see
other applications doing. It would be nice if the JRE would take care of that for us
and just ignore the icons when running on Mac OS X.

Objective-C/Java interaction

I have some java code that I use on a windows machine that runs as a service and has a tray icon that I want to port to Mac OS X. From what I can tell there is no good way to make a menu bar icon using java, so I want to basically wrap my java code with objective-c so I can have a nice menu bar icon and still interact with the java code as I am able to when running the code on my windows box. Is there a good way to do this?
My java code makes web requests every so often so the main functionality I'm looking for is to start/stop the web client, as well as receive updates from the java code on the status of the web requests (more or less push notifications).
Thanks for your help everyone!
If all you're trying to do is get your application's icon displayed in the Dock & the Finder, you don't need to write an objective-C wrapper; all you need to do is bundle the Java code up in with the icons in an OS X "application bundle". See Apple's Java Deployment Guide
You might also want to look into the com.apple.eawt package (see questions/1319805/java-os-x-dock-menu), which provides some features to allow a Java app to appear more like a native OS X application to the user (for example, supporting drag-and-dropping a file to the application icon).

Categories