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.
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.
How do you add the file icon to the titlebar in JavaFX on Mac?
Like this:
And how do you indicate that the document hasn't been saved, like this:
In Swing, this is how you do it, but is it possible in JavaFX too?
No pre-coded solution in this answer. The feature you request is not available out of the box with JavaFX 8.
Some approaches you could consider:
See: JavaFX entirely customized windows? and the Undecorator project. Potentially you could use something like Undecorator in conjunction with resources from AquaFX to achieve what you want.
OR
Another way is to use two stages layered on top of each other, the top stage being transparent and overlaying the icon on the lower stage - you would need to keep them in sync for location, size, visibility and iconification states.
Use a Swing stage and application which implements the icon and place the JavaFX content inside the Swing stage using a JFXPanel.
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
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
I'm trying to create a java desktop application that holds desktop icons. The app will be a menu/panel that is invisible until you hover your cursor near the top of the screen, at which point the menu full of desktop icons will drop down. To add new icons to the menu one must simply drag icons from the desktop into the menu and they should snap to grid. As I am an intermediate level programmer but I havn't ever done a GUI app before in any language, I was wondering if someone could help me out, both with how to approach the problem and on the packages and methods I should be using. Also, I'm thinking of doing this with NetBeans unless you have any other suggestions.
Thanks,
Andrew
As an alternative to Chad's option, you could also do this by creating a frame and using Java's transparent window capability to make the frame transparent (or translucent, if you want a hint that it's there), and using mouse entered/exited events to return the frame to its normal "solid" opacity.
Personally I'd try this solution just because I'd rather use event-based notification than polling the mouse position, but I expect it's more work than the other alternative.
As to drag and drop, I haven't used it extensively enough in Java to give any solutions, but it's not immediately obvious (from a cursory internet search) of how to handle native desktop drag and drops. I'd suggest starting with some dnd tutorials within an application so that you really understand Java's drag and drop API and capabilities.
You can use java.awt.MouseInfo to get the location of the mouse at any point in time, even if you don't have any windows open.
So, you could start a java program, then in your main loop poll the mouse location. If it's in the 'top', then you can open a window.
You can use the easiest thing to do would be to use JButtons or JLabels with images to represent the desktop icons. Just load the image you want to use and stick that on as a label.
I'd start by going through swing tutorial and writing a few simple GUI programs to get the hang of it.
But the MouseInfo thing is what you need to tell when the mouse is at the top of the screen.