Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reserving the edge of the screen in Java

Tags:

java

swing

awt

How can I make a window (such as a java.awt.Frame, javax.swing.JFrame, java.awt.Dialog, javax.swing.JDialog, etc.) reserve the edge of the screen, like a dock, taskbar, Trillian, or Microsoft OneNote can? I aim to only use standard JDK libraries if possible.

like image 790
Ky. Avatar asked Jan 11 '11 16:01

Ky.


People also ask

How do you set a frame border in java?

You can't have a border directly on a JWindow or JFrame. You need to put a JPanel with the desired border using the default JWindow/JFrame LayouManager (a BorderLayout). Then the JPanel is extended giving the impression that its borders are the JWindow one.

How do you specify the orientation of a BoxLayout?

You simply substitute X for Y, height for width, and so on. Version note: Before JDK version 1.4, no constants existed for specifying the box layout's axis in a localizable way. Instead, you specified X_AXIS (left to right) or Y_AXIS (top to bottom) when creating the BoxLayout .

What is BoxLayout in java?

public class BoxLayout extends Object implements LayoutManager2, Serializable. A layout manager that allows multiple components to be laid out either vertically or horizontally. The components will not wrap so, for example, a vertical arrangement of components will stay vertically arranged when the frame is resized.


1 Answers

This behaviour is very specific to the Windows operating system, and as such there is no way to do this in the standard JDK or with AWT/Swing, since these need to work consistently across a number of different operating systems.

The closest equivalent to what you want is to get the current screen's boundaries and move/resize your window to fit flush against one side, although this will now have any effect on the desktop or other windows.

The closest thing you will probably get to what you want is by using JNIWrapper and WinPack to alter the native window behaviour. Their documentation doesn't show anything about desktop toolbars, though. You would probably have to use their JNI to access the specific COM functions directly and then find out how to do it in C++, but if you don't know C++, that's probably out of the scope of your project.

Addendum:

If you want to make use of the native features for specific operating systems and desktop managers, you will need to connect with a native C++ library to hook into Gnome, KDE, Mac OS etc. Search for 'Java JNI' and the windowing system you want to integrate with to find packages you can use. For instance, for Gnome, see here.

If you want to support multiple operating systems, make sure you create a common interface so you can make implementations that connect with the respective JNIs depending on which one is available at runtime, and allow fallback if none of them are available.

PS. If you want popup notifications in your app, Mac OS and various Linux builds support Growl so that can save you some time.

like image 123
BoffinBrain Avatar answered Oct 28 '22 11:10

BoffinBrain