This is most likely an obvious question, but I was wondering how I can keep a program behind all other windows (except the desktop)?
In a way, I am trying to achieve the opposite of keeping a window in the front.
Here's an example:
Window 1
Window 2
Random Window
My App
Desktop
However, I need it so that it will always stay against the desktop, so you cannot interact with it unless you're looking at the desktop itself.
public void toBack()here
If this Window is visible, sends this Window to the back and may cause it to lose focus or activation if it is the focused or active Window.
Places this Window at the bottom of the stacking order and shows it behind any other Windows in this VM. No action will take place is this Window is not visible. Some platforms do not allow Windows which are owned by other Windows to appear below their owners. Every attempt will be made to move this Window as low as possible in the stacking order; however, developers should not assume that this method will move this Window below all other windows in every situation.
4 Years late, but if you need the window to always stay in the back, even when the user clicks on it, you can use:
JFrame frame = new JFrame("");
frame.setFocusableWindowState(false);
frame.toBack();
setFocusableWindowState(false) prevents the activation of the window when clicked.
Related
When I type dot and press ctrl+space, I see a pop-up with list of possible methods.
when I press ctrl+q i see another pop-up with javadoc for the selected method.
The problem is half of the popup is on the one screen and second half is on another screen. it's unreadable. how to make the pop-up stay on one screen?
ubuntu 14.04, mate, 2 monitors (extended desktop), intellij 2016.1.1
The pin is your friend!
Press that pin in the top right corner to "Open as tool window"!
From that moment on, the documentation will always appear in that specific window. Just resize it and place it somewhere in your screen where it does not interfere with other things. From that moment on, every time you press Ctrl + Q the documentation will appear in that window.
Also, note you can change the font size:
But it may be more handy to drag the popup with the mouse:
I want to have one main window, and inside that window should be child windows, which are draggable, resizable etc. If I use just JFrames or JDialogs, it gives me many problems about the stacking of the windows. When the main window has focus, the child windows shouldn't move to the background.
This can be so-so fixed by listening to window events and bringing the child windows to front again, but now I get even more problems, for example popup boxes and other prompt dialogs are not stacked in the right order.
My solution is to use JInternalFrame for the child windows, but the disadvantage is, that they are clipped by the parent container.
Here's an example (just from internet). You see the clipping of internal frames:
My question is: is it possible to make them visible outside the parent component, so the overflow is visible.
The final goal of the GUI is to get something like photoshop. Windows which are independent on the screen, but which will never go to the background of its main window (parent)
What's the main difference between the method windowActivated (implemented from WindowListener) and windowGainedFocus (implemented from WindowFocusListener)?
The Java documentaion says:
windowGainedFocus:
Invoked when the Window is set to be the focused Window, which means that the Window, or one of its subcomponents, will receive keyboard events.
windowActivated:
Invoked when the Window is set to be the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.
But what's the difference? Or is it just as it says, that a focused window is a type of activated window?
Thanks in advance!
From How to Write Window Listeners which reflects the quote in your question aswell:
windowActivated(WindowEvent) and windowDeactivated(WindowEvent):
Called just after the listened-to window is activated or deactivated,
respectively. These methods are not sent to windows that are not
frames or dialogs. For this reason, the windowGainedFocus and
windowLostFocus methods to determine when a window gains or loses the
focus are preferred.
So windowActivated is only executed when the window is a frame or dialog, while the windowGainedFocus is for all types.
The focused window is the one that receives keyboard input.
An active window is typically the document window that the user is manipulating.
An active window is generally distinguished visually, for example, with a different title bar.
In macOS, the focused window is called the key window and the active window (there can be only one) is called the main window.
The distinction is subtle because they are almost always the same window.
An example where they differ would be a floating palette that contains a text field. The palette would need to be the focused window to accept keyboard input, but the document window is the active window where the changes are actually made and it should be distinguished from other (inactive) document windows.
Although Java distinguishes active and focused windows in its API, the implementation links them together so that some combinations (like the above example) are not possible, or at least difficult to arrange. For example, if you click on a focusable Java window, it becomes both the focused window and the active window.
I have an application that uses the JOptionPane.show* methods to inform the
user about various conditions before displaying the applications main window.
On a multi screen setup these always show on the first screen. This is usually only
a minor annoyance, but becomes a problem when the 0 screen is off or disconnected.
Normal windows can be placed correctly using the GraphicsConfiguration obtained
via MouseInfo, but I can't find a way to pass that to JOptionPane. I can
not either use the main window to anchor the dialogs, because there is no main
window at that stage of the application startup. Among the possible dialogs is
a warning about obsolete java versions, so displaying the main window before the
errors is not option since the user's java runtime may not even be capable of
displaying the main window.
Is there a way to specify the target screen without reimplementing a major part
of JOptionPane?
You can create a JDialog out of a JOptionPane, and then display the dialog any location that you desire.
As per the JOptoinPane API:
JOptionPane pane = new JOptionPane(arguments);
pane.set.Xxxx(...); // Configure
JDialog dialog = pane.createDialog(parentComponent, title);
// here set the dialog's location
dialog.setVisible(true);
Edit: Alternatively, you could simply create your own JDialog window de novo as per Andrew's great comment (that now no longer exists?).
I am trying to build a user alert mechanism by bringing up the window to the front and then flashing the icon on the screen for the user. I have two questions with regards to this approach:
How can you find the current window you are at in Java and then de-minimize it and bring to front?
Is there a mechanism in Java that would enable me to simply show the icon for a second or two and then hide it, in the middle of the screen? If not, what would be the way to achieve that?
Thanks a lot for any replies.
How can you find the current window you are at in Java and then de-minimize it and bring to front
Window[] allWindows = Window.getWindows();
returns arrays of all Top-Level Containers from current JVM e.g. J/Frame, J/Dialog(JOptionPane), J/Window,
you can to test for (example) if (allWindows[i] instanceof JFrame) {
then WindowState returned WindowEvent
by bringing up the window to the front and then flashing the icon on the screen for the user
use undecodated JDialog (works toFront, toBack) with
create only once time
setDefaultCloseOperations(HIDE_ON_CLOSE)
use Swing Timer for hide JDialog
Is there a mechanism in Java that would enable me to simply show the icon for a second or two and then hide it, in the middle of the screen? If not, what would be the way to achieve that?
have look at Java Translucent Window, put there Icon to the JLabel (or to the JButton)
use Swing Timer for flashing by hiding Icon or swithing bewtween two or more Icons (three or four is good)
I think the simplest way to get the window ancestor is :
SwingUtilities.getWindowAncestor(yourComponent);