1

I am using JWindow in my project to display a UI that is undecorated and also doesn't appear in the task bar. But, the JWindow always seems to be on top of all other windows. I tried setting the setAlwaysOnTop to false, but it didn't seem to help.

Here's the code that can reproduce the problem :

package test;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JWindow;

public class Test extends JWindow implements ActionListener {

    public Test() {
        setSize(300, 300);
        setLocationRelativeTo(null);
        setAlwaysOnTop(false);

        JButton myButton = new JButton("Click Here");
        myButton.addActionListener(this);
        getContentPane().add(myButton);

        setVisible(true);
    }

    public static void main(String[] args) {
        new Test();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("Click Here"))
            JOptionPane.showMessageDialog(this, "This dialog box appears behind the JWindow!");
    }
}

My OS is Linux and I'm using the Oracle JDK 6. Also, while I was testing my app on Windows, I was using JDialog for the UI and it was working fine. But, in Linux JDialog seems to appear in the task bar.

Any help as to how to solve this?

Alexandru Chirila
  • 2,274
  • 5
  • 29
  • 40
  • [seems like as common issue for Modal and ModalityTypes on Linus, have to test](http://stackoverflow.com/questions/14645761/modal-dialog-not-always-on-top-of-an-undecorated-jframe-when-another-jframe-is-v) – mKorbel Feb 06 '13 at 13:25
  • I don't think it's a problem with Modality. I'm able to access other windows as well as applications when the JWindow is on top. But, the JWindow doesn't go back, it always stays on the top. – Karthik Prabhu Feb 07 '13 at 08:08

1 Answers1

0

After you set the visibility of the window to True, you send it to the back like this:

setVisible(true);
toBack();

If, later, you want to bring it to the top of the stacking order, you simply call:

toFront();

More details here:

http://docs.oracle.com/javase/6/docs/api/java/awt/Window.html#toBack()

http://docs.oracle.com/javase/6/docs/api/java/awt/Window.html#toFront()

Alexandru Chirila
  • 2,274
  • 5
  • 29
  • 40
  • Thanks for the reply, but when I do toBack() it only sends it back of the stacking order within the application. The JWindow still stays on top of all other applications that are running. – Karthik Prabhu Feb 06 '13 at 14:29
  • Oh, I understand now, well that's mostly the OS's problem, because the JAVA VM does not have access to the OS's visual decorator. Also in the documentation: http://docs.oracle.com/javase/1.5.0/docs/api/java/awt/Window.html#setAlwaysOnTop(boolean) you will see this note: some platforms might not support always-on-top windows. There is no public API to detect if the platform supports always-on-top at runtime. – Alexandru Chirila Feb 06 '13 at 15:10
  • Also, what task bar in Linux ? You say that your OS is Linux, that is wrong, the kernel of your OS is Linux, but the OS is something else (Ubuntu, Fedora, OpenSuse, Debian etc...) All of these distribution work with different (possibily customizabile) decorators, and as I said the Java VM does not have access to them. If you want to research this further, find out what OS and decorator are you using, and possibily learn more about them. Although I cannot see any good reason you will need such a thing, I presume you have one.Also if you explain why you need this,we might give you an alternative – Alexandru Chirila Feb 06 '13 at 15:16
  • I'm sorry, I meant to say Linux Mint. And also my desktop environment is Mate. Basically, I'm developing a sticky notes app that uses the system tray as the main UI for managing the application. I was using JDialog to create the sticky notes. But, in Linux (I have tried other desktop environments too) it is visible in the taskbar which is undesirable in this case. So, now I'm using JWindow, but it just stays on top of all windows. You can check out the project here : [JStickies](http://karthikprabhu.github.com/jstickies/) – Karthik Prabhu Feb 06 '13 at 16:00
  • Ok, so the problem is not that it's on top of others windows, but it's the appearance in the "task bar". Have a look on this code https://github.com/alexkiro/TimrDesktop/blob/master/TimrDesktop/src/timr/tray/Notification.java It's an old notification system for an homework. It creates a small window, with a notification, that expires after a few seconds. This notification will not appear in the taskbar (as far as i remember). The code might be a little messy, but i hope it helps. It has something to do with setting the main component of the window to a JPanel instead of a JFrame – Alexandru Chirila Feb 06 '13 at 16:28
  • No, I've switched my application to JWindow, so it doesn't show up in the task bar now. Currently, the problem is that the JWindow is on top of all the windows, except for any frames or dialogs I create within my application. – Karthik Prabhu Feb 06 '13 at 16:38