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.
Related
I have an old .jar file that creates a main window with some textboxes for settings.
The problem is that some textboxes doesn't appear in the window (but they exist), if you lower the computer screen resolution they appear, but with higher resolutions, they disappear.
I tried to decompile the .jar file, but no success...
Since I cannot resize the window in any way (size seems to be fixed), is there a way to force it to be resized or set some Java VM parameters for this purpose?
The loader is "JarRsrcLoader". I attach an image showing the problem in Win10:
(They are not only cut, there are more textboxes).
I asked Mr Google for a Windows tool to make unresizable windows resizeable. Got several matches, here is a short list:
http://www.howtogeek.com/howto/11799/turn-non-resizeable-windows-into-rezieable-windows/
https://www.raymond.cc/blog/how-to-resize-an-unresizable-window-or-dialog-box/
http://www.ghacks.net/2012/06/18/resize-windows-with-fixed-sizes/
I actually found a way to scale the Java application to a lower resolution and see it adequately, only for Linux (but it was what I was searching).
From this source (askubuntu.com): script to fix scaling of java applications.
It provides python scripts to adjust the resolution of certain applications (statically and dynamically) when opened (on a high dpi screen). This solution works for my problem.
I'm developing a JavaFX Application, In here, the outer elements of the JavaFX Window Changes across different Operating System's, i.e. The Position of Close, Minimize and Maximize Window is on left on Mac OS X and on the right in the Windows, Also there Shapes are Different as The OS Changes.
Also if the Application is Running Under OS X, it has drop shadow effect along the boundaries, which in case of Windows is Not Present :
And Want My JavaFX Application to look exactly the Same, Regardless of Operating System, it is Being Run On. How Can i Achieve this ?
Use the undecorator project.
Decorate undecorated JavaFX stages with custom skin. This helper brings a custom look to your JavaFX stages.
See also:
JavaFX entirely customized windows?
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
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.
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.