Is there a way to create a window using Swing or AWT that behaves and looks like an inspector window on Mac OS X? An example of an inspector window would be the window that opens in Finder when Command-Option-I is pressed.
I'm looking for a way to create a window that has a half-height title bar, that always stays on top and that does not get focus e.g. when dragged around.
It is only necessary for the solution to work on Mac OS X, so platform-specific libraries are allowed. But if there is a standard way, event if it has minor drawbacks, it is preferred.
Leopard added some Swing client properties to improve the UI of OS X Java apps – these are described in Technical Note TN2196. The one you're looking for is Window.style:
This property determines if the window has a Utility-style title bar. In order to make this window style also float above all others you must additionally call setAlwaysOnTop(true). Windows that have both the "small" style and are set to always be on top will automatically hide themselves when your application is no longer frontmost. This is similar to how native applications behave.
This property has to be set on the JRootPane of a window before it's native peer is created:
dialog.getRootPane().putClientProperty("Window.style", "small");
ModalityTypes are platform dependent, you have to look for JDialog#ModalityTypes
Related
I know in java-fx to make the window transparent, you need to set the stage style as stage.initStyle(StageStyle.TRANSPARENT);. However this will also remove any stage decorations so this does not solve my problem.
The reason I need this is because my application will need to use stage.setAlwaysOnTop(); at certain points, but this feature is not well supported on the target system (centOS). The application also requires stage.setIconnified();, but this does not work if the stage is undecorated.
Any suggestions will be appreciated.
Thanks
The short answer would be "no, you can't" ... because the minimize/maximize/close buttons are part of the decoration. No decoration - no buttons. It would be a contradiction in itself.
If you need the functionality of those buttons, you would have to create your own buttons as a part of your UI and emulate the behaviour of the decoration buttons. That's what many apps do that come with no default decoration.
Anyway, if you want to manipulate the window behaviour in this way (stay-on-top/iconify, etc.) you always need to take the underlying operating system into account. Any apps (not only Java apps) are only allowed to interfere with window management as far as the OS windowing system allows them to do so.
For example, in various MS Windows versions, the OS behaviour changed several times at this point.
I'm using a robot to click on a certain point on the screen. I just need a way for the robot to bring the desired window to focus. Now here's where the real problem lies, the window is a Java window, but not one I made. I used a VBscript to focus on Firefox earlier, but I'm not sure what to do. When I mouse over the icon on my toolbar, it says the windows name is "BitMinter Client v1.4.2" but in Task Manager it calls the process "Java(TM) Platform SE binary (32 bit)?
How do I focus in on the window?
Having the robot input ALT+TAB won't work because the window isn't second on my ALT+TAB list.
AppActivate looks for matching Window's titles.
Use spy++ (Windows SDK and most MS development tools) to get the window title.
You mention firefox so I don't know what type of Window you are referring to. In IE most web page elements (and for that matter very many other Window's things) haven't been Windows for decades. I don't know how firefox or java are implemented.
Windows basic architecture is windows (such as edit controls/buttons) inside other windows (a pane) inside a top level window (ie notepad) inside the desktop window.
To take notepad. There is a main window, menu bar, statusbar window, edit control window. Each of them has a title and class. This is notepad's title and class.
Untitled - Notepad Notepad
«No Window Text 0» Edit
«No Window Text 0» msctls_statusbar32
I would like to have an application where I've entirely customized the window's appearance. So far I've learned that I can remove the typical window stuff with:
class Application extends javafx.application.Application {
/**
* Starts the application.
*
* #param stage
*/
override def start(stage: Stage) {
stage.initStyle(StageStyle.TRANSPARENT)
// Load the main window view.
val loader = new FXMLLoader()
loader.setLocation(getClass.getResource("/com/myproj/application/MainWindow.fxml"))
val root = loader.load().asInstanceOf[Parent]
val scene: Scene = new Scene(root, Color.TRANSPARENT)
stage.setScene(scene)
stage.show()
}
}
Everything else works fine, except that window dragging, double-click-to-maximize, dragging to screen top edge on Windows should active maximizing, etc. The native Window capabilities are missing entirely.
Can I somehow rather easily customize the entire appear of the window without losing all these nice capabilities.
I'm talking about something like Adobe Photoshop which looks entirely different but still retains these features (or implements them on top of their UI manually).
It would be a start if I could at least implement dragging + window buttons for starters. I am targeting Linux, Mac and Windows here.
See the customized window appearance and handling in the Ensemble Sample application, which includes source code. Download the source, build it and run it as a standalone application rather than embedded in a browser. It isn't going to be exactly what you are asking for because stuff like dragging to screen top edge to activate maximizing isn't going to work I think, but it should be very close and you could always code something yourself which maximized the window when it was dragged near the top edge. The Ensemble window has features like custom resize decorations, minimize, maximize, close icons, an area at the top of the window you can use to drag the window around or double click to maximize or minimize the window - i.e. most of the standard features you would expect from a desktop windowing system.
To get something even closer to what you are asking, perhaps you could hack something together by creating two windows. One, a standard decorated stage window which includes screen borders, the other an undecorated or transparent child stage always displayed on top of the main window and overlaying the borders of the main window with a custom rendering. I think you may run into difficulties trying to implement this approach, so I wouldn't really recommend it.
You may like to try an UNDECORATED stage style rather than TRANSPARENT and see if you get better native Windows integration with that.
There are some open feature request currently scheduled for JavaFX to be shipped with JDK8, Windows: support Aero Glass effects for top-level windows, Mac: Support NSTexturedBackgroundWindowMask style for windows and The solid white background created in a Stage should be created - if needed - in the Scenegraph, which, when implemented, will likely help you to acheive your goal - vote for them, if such features are important to you.
Also checkout VFXWindows which is an open source windowing framework for JavaFX.
Update
Also related is the Undecorator project which allows you to easily create a JavaFX stage with standard minimize/maximize/close/resize chrome controls that are rendered via the JavaFX engine rather than the OS windowing system. This allows you to achieve the kind of custom control over window rendering that an application like Ensemble displays.
You can use this library. It is a fully customizable JavaFx Stage (CustomStage). You can see in-detail description of how to use it in this CustomStage Wiki
It has,
Window resizing
Default action buttons and their behaviour (close, maximize/restore, minimize)
Window dragging
Window is automatically scaled as for screen resolution
Very responsive
Stylable (via css and methods)
Can achieve transparency
Has in-built navigation panes and drawers
etc.
For reasons of aesthetics and usability, my program uses an undecorated Stage.
I have implemented the core functions - minimize, maximize, close, resize and drag are all present.
Now, I discovered that the program is lacking some advanced features that I took for given:
On a Windows XP system, clicking the program's entry in the taskbar no longer minimizes it.
On a KDE system, dragging does not allow any part of the Stage to leave the screen.
Each feature is present on the respective other system; both work on each system when the stage is decorated.
I would like to whether I can somehow re-create this behaviour in my program without reverting to a decorated stage. The Stage API does not seem to offer anything helpful.
A hack to get this to work might be to create a decorated stage as the parent of your undecorated stage. Position the decorated stage so that it is hidden behind the undecorated stage. Functionality like clicking on the program's entry in the taskbar should work (and hopefully the hacked arrangement won't cause other insurmountable issues). You'll need listeners on visible and hidden states of your windows and tracking of their size so that you can correctly maintain the relationships between the top undecorated window and the hidden decorated window. You can request official APIs which more directly provide the functionality you are seeking at http://javafx-jira.kenai.com
I'm developing a desktop application using Java. I want to put an icon (with a contextual menu) on the system tray (called Menu Extras in Mac Os). Java 6 comes with support for doing this in Windows and Linux, but it doesn't work in Mac Os.
I have seen some applications doing what I want in all three operating systems (e.g. DropBox), but I don't know if they are made with Java.
How can I achieve this?
If it's not possible in Java, is there any other cross-platform language able to do that?
Thanks.
AWT / Swing
According to documentation, OSX 10.5 update 1 and newer support TrayIcons
TrayIcons are represented on Mac OS X
using NSStatusMenus that are presented
to the left of the standard system
menu extras. The java.awt.Image
artwork for a TrayIcon is presented in
grayscale as per the Mac OS X standard
for menu extras.
TrayIcon.displayMessage() presents a
small non-modal dialog positioned
under the TrayIcon. The ActionListener
for the TrayIcon is only fired if the
"OK" button on the non-modal dialog is
pressed, and not if the window is
closed using the window close button.
Multiple calls to
TrayIcon.displayMessage() will dismiss
prior messages and leave only the last
message. If the application is not in
the foreground when
TrayIcon.displayMessage() is called,
the application bounces its icon in
the Dock. Message windows are badged
with the application's icon to
identify the which application
triggered the notification.
noah provided this sample:
java.awt.SystemTray.getSystemTray().add(new java.awt.TrayIcon(java.awt.Toolkit.getDefaultToolkit().getImage("foo.png")));
Note that you'll probably want to attach a menu to that icon before adding it to the tray, though.
SWT
According to documentation, SWT 3.3 and newer supports TrayItem icons on OSX.
Icons placed on the system tray will now appear when running on OS X in the status bar.
This snippet shows how to create a menu and icon and put them in the Tray.
I ported a Windows application to my Mac with little difficulty. One thing I noticed is that the icons are in full, living color (not following the Mac convention). I'll need to add a little OS-specific code to convert myself. But this is a big step up from the DLL dependent Desktop integration version from earlier iterations of Java.