Windows
Window Management
Java
Glue42 Windows
In order for windows created from an external Java applications to become Glue42 windows, these windows must first be registered via the Java Window Management API.
Window Types
The window type is controlled by the mode
window option which can be specified in the application definition or during window registration:
windows.register(handle, options -> options.mode(WindowMode.FLAT));
Registering a Swing Window
Currently, Glue42 Windows requires the underlying native handle (hwnd
in the case of Windows) to be initialized and attached to the JFrame
before the window can be registered. This is achieved internally through Glue42 Windows.
WindowManager windows = glue.windows();
WindowHandle<JFrame> handle = windows.getWindowHandle(frame);
windows.register(handle)
.thenAccept(window ->
frame.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
window.closeAsync();
}
}));
Controlling the Window
Once an application window is registered, Glue42 Windows will accept full control over the window positioning, sizing and visibility. The application should not use native methods (for example, Swing calls) to control the window as it will interfere with the Glue42 window management.
The Java Window Management API allows you to control the following window properties:
Title
The following example demonstrates how to set the window title during the window registration (this will ignore the title specified in the application configuration):
glue.windows().register(handle, options -> options.title("My Title"));
To change the window title at runtime, use the changeTitle()
method of a Glue42 Window instance and pass the new title as an argument:
window.changeTitle("New Title");
Size and Position
Change the window bounds:
window.changeBounds(new Bounds(10, 10, 200, 200));
Visibility
Note that changing the window visibility also affects its associated icon:
window.changeVisibility(false);
Frame Buttons
You can put extra buttons in the frame area of the window and handle clicks for those buttons.
Adding a New Button
Use the addFrameButton()
method to add a new button:
window.addFrameButton("search-button",
ButtonOptions.builder()
.toolTip("Search")
.order(1)
.image(new byte[0]) // needs to be a valid image
.build())
.thenRun(() -> System.out.println("created button"));
Removing Button
Use removeFrameButton()
to remove a button from the frame:
window.removeFrameButton("search-button")
.thenRun(() -> System.out.println("removed button"));
Handling Clicks
Use onFrameButtonClicked()
to subscribe for button clicks:
window.onFrameButtonClicked(e -> {
if ("search-button".equals(e.getButtonId()))
{
System.out.println("Search button clicked");
}
});