Link to home
Start Free TrialLog in
Avatar of mcgirk
mcgirk

asked on

setVisible(false) - how can I show it again

I've got a Java Application that extends Frame.

At a certain point, I want to hide it without showing it on the taskbar so I setVisble to false.  Is there a way to get it back?  If possible, I'd like to use a icon on the desktop, double click it and show the window again.
Avatar of JK2429
JK2429

Yes.  Set up a boolean value.
After minimizing, if you click on the icon, it would execute the function which will make your window appear again thus as you click on the icon, your boolean value is set to true.
Avatar of mcgirk

ASKER

What does the icon point to?
The only thing I can think of is to make it a batch file and run a java command?  Can you give me an example?
You could make a JAR file with a class that sets visibility to true; however, you'd need to use sockets or CORBA to accomplish this. It'd be much better if you could keep it in one program (another frame perhaps, a timer, etc.).
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you wanted to be really utilitarian (and take up as little screen space as possible),  you could create a frame and give it a window destroyer method that sets the first frame to be visible:

In your main class:

JFrame tempFrame = new JFrame();
tempFrame.setSize(1,1);
WinListener winListener = new WinListener();
tempFrame.addWindowListener(winListener);
tempFrame.setVisible(true);

Class WinListener:

import java.awt.*;
import java.awt.event.*;

public class WinListener extends WindowAdapter{

public void windowClosing(WindowEvent evt){
MainClass.invisibleFrame.setVisible(true);
}
}

NOTES: MainClass is the name of the main class and invisibleFrame is the name of the frame to make visible. invisibleFrame has to be declared outside of a method for this to work (i.e. globally).
that will show the frame in the task bar.
Hrmm... good point (but would it matter in this case? Isn't it only the hidden frame that needs to stay out of the taskbar?). My problem with a dialog is that he may be trying to run some other tasks while the frame is hidden which would require him to make a new thread (which while not very hard as you've taught me, could be a bit annoying if not necessary...).