使Java应用程序对用户不可见

时间:2012-02-21 02:20:14

标签: java swing jframe trayicon jwindow

我正试图想出一种让用户看不到Java应用程序的方法。

基本上只是尝试删除this

task bar icon< - 图片

如何做到这一点?

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

3 个答案:

答案 0 :(得分:5)

我似乎已经找到了答案,只需将行setVisible(false);放入注释中,您将看到实际的程序,UNCOMMENT该行看不到任何痕迹,据我所见, Java程序正在某处运行,直到您不会手动将图标添加到系统托盘中。此外,如何从任务管理器中删除您的应用程序,该问题仍然存在,但您可以删除所述图标,如您在问题中所指出的那样。

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

以下是运行此程序时桌面的快照,请参阅任务栏

JAVA APPLICATTION

答案 1 :(得分:4)

JWindow而不是JFrame延伸。 (我没有在Windows 7上进行测试,因为我现在没有坐在Windows机箱前面。它适用于XP,适用于Unity,让我感到惊讶。)

答案 2 :(得分:3)

据我所知,没有办法删除任务栏图标。

相关问题