Make a Java application invisible to a user

怎甘沉沦 提交于 2019-12-07 21:30:55

问题


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

Basically just trying to remove this

<- 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);
}
}

回答1:


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




回答2:


Extend from JWindow insted of JFrame. (I did not test this on Windows 7 as I don't sit in front of a Windows box right now. It worked for XP and works for Unity, which surprised me.)




回答3:


As far as I know, there is no way to remove the task bar icon.



来源:https://stackoverflow.com/questions/9371258/make-a-java-application-invisible-to-a-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!