Search code examples
javaswingjframetrayiconjwindow

Make a Java application invisible to a user


I'm trying to figure out a way to make a Java application invisible to the user.

Basically just trying to remove this

task bar icon <- Image

How can this be done?

public class TransparentWindow extends JFrame {

public TransparentWindow() {
    initComponents();
}

@SuppressWarnings("unchecked")
private void initComponents() {
    setExtendedState(Frame.MAXIMIZED_BOTH);
    setResizable(false);
    setUndecorated(true);
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    setAlwaysOnTop(true);
    System.setProperty("sun.java2d.noddraw", "true");
    WindowUtils.setWindowTransparent(this, true);
    WindowUtils.setWindowAlpha(this, 0.6f);
}

public static void main(String[] args) {
    new TransparentWindow().setVisible(true);
}
}

Solution

  • I just seems to have found the answer, just put the line setVisible(false); into comments and you will see the actual program, UNCOMMENT the line to see no trace is left, as far as I can see, that the Java Program is running somewhere, until you won't add the icon to your system tray, manually. Moreover how to remove your Application from Task Manager that question still remains, though you can remove the said icon, as pointed by you in your question.

    import javax.swing.*;
    
    public class TransparentWindow extends JFrame 
    {
        public TransparentWindow() 
        {
            initComponents();
        }
    
        @SuppressWarnings("unchecked")
        private void initComponents() 
        {
            setExtendedState(JFrame.MAXIMIZED_BOTH);
            setResizable(false);
            setUndecorated(true);
            setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
            setAlwaysOnTop(true);
            setOpacity(0.8f);
            setSize(200, 200);
            //System.setProperty("sun.java2d.noddraw", "true");
            //WindowUtils.setWindowTransparent(this, true);
            //WindowUtils.setWindowAlpha(this, 0.6f);
            setVisible(true);
            setVisible(false);
    
            JOptionPane.showMessageDialog(this, "It is working!", "Guess : ", JOptionPane.INFORMATION_MESSAGE); 
        }
    
        public static void main(String[] args) 
        {
            TransparentWindow tw = new TransparentWindow();
        }
    }
    

    Here is a snapshot of my desktop on running this program, see the taskbar

    JAVA APPLICATTION