Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 how to check if window is visible?

View previous topic View next topic Go down 
AuthorMessage
Tiger
Member
Member
Tiger

Posts : 7
Join date : 2011-04-17

how to check if window is visible? Empty
PostSubject: how to check if window is visible?   how to check if window is visible? EmptyWed May 11, 2011 11:27 pm

hello,

i have a simple program that opens nested in the icontray ( windows ).

this part works fine, I can launch the program from there, however if I can click more then once and the program opens several times. so i'm wondering how can i check it the window is already open and if it is, simple minimize it back to the icon tray?


my code thus far;
Code:

public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
               
                ShippingQuote application = new ShippingQuote();
                application.getJFrame().setVisible(true);

                if (SystemTray.isSupported()) {
                    SystemTray tray = SystemTray.getSystemTray();

                    trayIcon.setImageAutoSize(true);
                    trayIcon.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {

                            ShippingQuote application = new ShippingQuote();
                            application.getJFrame().setVisible(true);
                         
                      }
                    });

                    try {
                      tray.add(trayIcon);
                    } catch (AWTException e) {
                      System.err.println("TrayIcon could not be added.");
                    }
                  }
               
               
            }
        }); 
Back to top Go down
Skilletrockz
Super Moderator
Super Moderator
Skilletrockz

Posts : 45
Join date : 2011-05-11

how to check if window is visible? Empty
PostSubject: Re: how to check if window is visible?   how to check if window is visible? EmptyWed May 11, 2011 11:28 pm

It won't quite work with what you have, your listener is spawning a new instance each time (assuming that the getJFrame indicates that the ShippingQuote contains a frame / is a frame).
Here's a quick mish-mash I put together. I choose to use a mouseevent instead since I added the display text. Clicking the balloons would trigger the action event which is also not super if you wanted to use the balloon. I also don't like the double click force, so I like the click control instead.
Code:

public class Frametest extends JFrame
{
    public static void main(String[] argv)
    {
        final Frametest f = new Frametest();
        f.setSize(100, 100);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        if (SystemTray.isSupported())
        {
            SystemTray tray = SystemTray.getSystemTray();
            try
            {
                ImageIcon i = new ImageIcon("C:\\java.jpeg");
                TrayIcon ti = new TrayIcon(i.getImage());
                ti.setImageAutoSize(true);
                ti.addMouseListener(new MouseAdapter(){
                    @Override
                    public void mouseClicked(MouseEvent e)
                    {
                        super.mouseClicked(e);
                        e.consume();
                        if (e.getButton() == MouseEvent.BUTTON1)
                        {
                            TrayIcon ti = (TrayIcon)e.getSource();
                            ti.displayMessage("Frame Toggle", f.isVisible() ? "Closing frame..." :
                                            "Opening frame...", MessageType.INFO);
                            f.setVisible(!f.isVisible());       
                        }
                    }
                });
               
                tray.add(ti);
            }
            catch (Exception ex)
            {
                System.err.println(ex.getMessage());
            }
        }
        else
        {
            f.setVisible(true);
        }
    }

Back to top Go down
Tiger
Member
Member
Tiger

Posts : 7
Join date : 2011-04-17

how to check if window is visible? Empty
PostSubject: Re: how to check if window is visible?   how to check if window is visible? EmptyWed May 11, 2011 11:29 pm

thanks! i'll give this a shot
Back to top Go down
Sponsored content




how to check if window is visible? Empty
PostSubject: Re: how to check if window is visible?   how to check if window is visible? Empty

Back to top Go down
 

how to check if window is visible?

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» how to resize window ie6
» Need link to open in same window...
» Displaying 'terminal stuff' in a window
» Twitter retweet script printing authorize url in browser window and also not redirec
» regex check please.

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: how to check if window is visible? Edit-trash Useless :: Trash-