Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2005

Tip: Looking for answers? Try searching our database.

How to display window after windowClosing() event.

Thread view: 
Milind - 04 Feb 2005 13:36 GMT
Hi,
I have the following code in windowClosing() of JFrame in Mac

public void windowClosing(WindowEvent event)
{
   setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}

Hence after I click on the close button, window won't be visible.
But the .app is available in the dock menu of Mac.
How can I make the window visible if I click on the .app icon in dock.
Please let me know.

Thanks in advance.
Milind
Thomas Weidenfeller - 04 Feb 2005 14:05 GMT
> Hi,
> I have the following code in windowClosing() of JFrame in Mac
[quoted text clipped - 3 lines]
>     setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
> }

That code does not make much sense. One is supposed to set the default
closing behavior outside of an event handler. Then, especially in case
you use DO_NOTHING_ON_CLOSE, you can implement your own closing behavior
in an windowClosing() event handler. Q5.7 has an example. May I suggest
that you check out Sun's GUI tutorial, too, especially

http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html

As for integrating Java and Mac OS X, see e.g.

http://java.sun.com/developer/technicalArticles/JavaLP/JavaToMac1/
http://java.sun.com/developer/technicalArticles/JavaLP/JavaToMac2/
http://java.sun.com/developer/technicalArticles/JavaLP/JavaToMac3/

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

Thomas Weidenfeller - 04 Feb 2005 14:13 GMT
> Q5.7 has an example.

Ups, that should read Q5.7 of the FAQ has an example.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

milindsj@gmail.com - 04 Feb 2005 14:39 GMT
Hay thomas,
 sorry for posting the question in 2 groups.
 I went through Q5.7.
 I can do the DO_NOTHING_ON_CLOSE outside windowclosing() and do
HIDE_ON_CLOSE in windowclosing(). But my problem is once the window is
invisible on close. How should I make it visible again. I have the .app
for my application when the window is hidden on close, if I click on
the app in dock, it should display the window again. Thats what is not
happening. Please help me out.
Thanks again.

Milind
Thomas Weidenfeller - 04 Feb 2005 14:46 GMT
> Hay thomas,
>   sorry for posting the question in 2 groups.
>   I went through Q5.7.
>   I can do the DO_NOTHING_ON_CLOSE outside windowclosing() and do
> HIDE_ON_CLOSE in windowclosing().

Again, there is no point in setting HIDE_ON_CLOSE in windowClosing(),
unless you are doing something very special - something you didn't tell us.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

milindsj@gmail.com - 04 Feb 2005 15:12 GMT
Here are the details,
  I need to hide my java application on click of close button.
  I did this by using the above code that i put it in earlier message.
  Now when I hide the application, I don't know how to make it visible
again. I have the .app icon present in the dock. So I expect if I click
on the .app it should be visible again and thats what is not
happening....
  Please let me know, how can I handle this?

Milind
Andrey Kuznetsov - 04 Feb 2005 16:44 GMT
>   I need to hide my java application on click of close button.
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

no need for any listener.

>   I did this by using the above code that i put it in earlier message.
>   Now when I hide the application, I don't know how to make it visible
> again. I have the .app icon present in the dock. So I expect if I click
> on the .app it should be visible again and thats what is not
> happening....

do you get some event if user clicks on the dock icon?

Signature

Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

milindsj@gmail.com - 04 Feb 2005 17:56 GMT
thats what problem is....
I dont get any event if user clicks on the doc icon....
do you have any idea?

Milind
Andrey Kuznetsov - 04 Feb 2005 19:09 GMT
> thats what problem is....
> I dont get any event if user clicks on the doc icon....
> do you have any idea?

this is very apple specific.
I am sure that apple has solution for that.
You should search in apple's libraries (apple.mrj...).

Signature

Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Bill Tschumy - 04 Feb 2005 20:02 GMT
> Here are the details,
>    I need to hide my java application on click of close button.
[quoted text clipped - 6 lines]
>
> Milind

To my knowledge there is no way in Java to get notified of a click on the
dock icon.  I'm sure you could add some native code to detect this and notify
your app if you wanted to go that route.

You might try this...

When you hide your window, create a small 1 pixel by 1 pixel JWindow (0 by 0
may work).  Add a WindowListener to it and when you get a windowActivated()
message, show the main window.

This will work to show the main window on a dock click **if your app is
currently not the active app**.  It works because clicking the dock icon will
activate the application and the small hidden window will get a
windowActivated notification.

Yes, it is a kludge....

Signature

Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com

Steve W. Jackson - 04 Feb 2005 20:48 GMT
> > Here are the details,
> >    I need to hide my java application on click of close button.
[quoted text clipped - 23 lines]
>
> Yes, it is a kludge....

Actually, there might be a way to get just what the OP is after.

First, as has been said to the OP numerous times in this thread, dump
that code that has a HIDE_ON_CLOSE in the windowClosing event.  It's
useless.  You're not understanding the difference between hiding a
window and hiding an application.  Simply call the JFrame's
setDefaultCloseOperation(HIDE_ON_CLOSE) to have it automatically hide
when its close decoration is activated.  There's no logical need to even
have a window listener involved if that's all you're attempting to do.

<http://developer.apple.com/documentation/Java/Reference/1.4.2/appledoc/a
pi/index.html> leads to Apple's API docs on Mac-specific extensions to
1.4.2.  Look at the Application class and the ApplicationListener
interface.  When the latter's handleReOpenApplication() method is
called, it's supposed to signal that a user has clicked the dock icon
for the application.  It can also get triggered if another application
generates an open request (say on a type of file you handle) to your
application.  This might well be the ideal spot to determine whether the
app's primary JFrame is visible and to make it visible if not.  And of
course it's got the hooks for responding to the About and Quit menu
items that are inherent in all OS X applications, among other things.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

milindsj@gmail.com - 04 Feb 2005 21:36 GMT
Thanks steve,
 it helped me alot. I didn't have any idea regarding the same. I was
really finding it very hard to cope up with Mac style coding.
 Thanks again...

Milind
milindsj@gmail.com - 05 Feb 2005 11:23 GMT
hello there,
 I have one more problem regarding apple menu.
 I could capture the handleAbout(ApplicationEvent event) as told by
you. But instead of the default dialog, I want to display my own
dialog, so i put the following code
public void handleAbout(ApplicationEvent event)
{
  C3PAboutDialog c3pAboutDlg = new C3PAboutDialog(m_this_object);
  c3pAboutDlg.show();
}
But the problem is, the application displays both the dialogs one put
by me and the default one too.
Can you help me out how to remove the default dialog?
Thanks in advance.

Milind
Bill Tschumy - 05 Feb 2005 14:51 GMT
> hello there,
>   I have one more problem regarding apple menu.
[quoted text clipped - 12 lines]
>
> Milind

You really need to spend some time looking through Apple's Java developer
documentation.  This is all covered.

In you handleAbout() method you need to indicate that you have handled the
event by doing:

appEvt.setHandled(true);

Signature

Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com

Steve W. Jackson - 07 Feb 2005 18:25 GMT
> > hello there,
> >   I have one more problem regarding apple menu.
[quoted text clipped - 20 lines]
>
> appEvt.setHandled(true);

Excellent advice.  In addition, there are a series of 3 articles on
bringing Java apps to Mac OS X.  They all date back to 2003, so that
some info refers to 1.4.1, but they're worth a look.  The first is at
<http://java.sun.com/developer/technicalArticles/JavaLP/JavaToMac/>, but
some improvements were made after it was written.  The second is at
<http://java.sun.com/developer/technicalArticles/JavaLP/JavaToMac2/> and
has an example of handling an About dialog (it also contains a link to
the first near its end).  The third and final article is available at
<http://java.sun.com/developer/technicalArticles/JavaLP/JavaToMac3/>,
also with links at its end to the first two.  It addresses packaging the
application.

But, as Bill has said, while these and other articles are helpful,
there's no substitute for Apple's own documentation.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.