问题
I'm trying to figure out a way to make a Java application invisible to the user.
Basically just trying to remove this
<- ImageHow 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