-
JFrame / JDialog issue
Hi All,
I have an application which initially runs in one JFrame. When the user selects
a Help menu item another JFrame opens and the user can switch between both
frames with no problems.
However, when I open a JDialog in the original frame you cannot navigate
in the second frame! Why is this so? The dialog belongs to the original frame.
The second frame belongs to nothing but does close automatically when the
first frame is closed.
Thanks,
Kent
-
Re: JFrame / JDialog issue
Hi Kent,
itīs a normal "limitation" to frames, they are not modal, which means
they donīt block other parts of the application until they have been closed.
Dialogs on the other hand are meant to require user action ( like
clicking on the okay button ) and thus halt all access to the calling
window / frame until the dialog is closed.
As far as i know it is not possible by standard means to make a JFrame
modal ( and let it act like a dialog that way ).
Your second frame closes automatically when you close the first frame,
because you most likely call the second from the first - that means the
first or "main" frame holds reference to the "child" ( just try to
picture it that way, for the second frame is actually no child in java
language terms ) frame.
When you close ( destroy ) the first window the reference to the second
frame is lost and it is cleaned up by garbage collection.
Hope that helps
Volker
Kent wrote:
> Hi All,
>
> I have an application which initially runs in one JFrame. When the user selects
> a Help menu item another JFrame opens and the user can switch between both
> frames with no problems.
>
> However, when I open a JDialog in the original frame you cannot navigate
> in the second frame! Why is this so? The dialog belongs to the original frame.
> The second frame belongs to nothing but does close automatically when the
> first frame is closed.
>
> Thanks,
> Kent
>
-
Re: JFrame / JDialog issue
Hi Volker,
Thanks for your reply. See my further comments / questions below.
Kent
Volker Held <vheld@gwdg.de> wrote:
>Hi Kent,
>
>itīs a normal "limitation" to frames, they are not modal, which means
>they donīt block other parts of the application until they have been closed.
Agreed.
>Dialogs on the other hand are meant to require user action ( like
>clicking on the okay button ) and thus halt all access to the calling
>window / frame until the dialog is closed.
Also agreed. The problem is my dialog (opened from frame 1) blocks access
to the second frame! Why is this? I have set my dialog owner to frame 1 via
the JDialog constructor.
Further to this I tried opening a JDialog from frame 2 and this blocked access
to frame 1! What the...?
>
>As far as i know it is not possible by standard means to make a JFrame
>modal ( and let it act like a dialog that way ).
>
>Your second frame closes automatically when you close the first frame,
>because you most likely call the second from the first - that means the
>first or "main" frame holds reference to the "child" ( just try to
>picture it that way, for the second frame is actually no child in java
>language terms ) frame.
Yes, I agree - that is exactly what is happening.
>When you close ( destroy ) the first window the reference to the second
>frame is lost and it is cleaned up by garbage collection.
>
>Hope that helps
>
>Volker
>
>Kent wrote:
>> Hi All,
>>
>> I have an application which initially runs in one JFrame. When the user
selects
>> a Help menu item another JFrame opens and the user can switch between
both
>> frames with no problems.
>>
>> However, when I open a JDialog in the original frame you cannot navigate
>> in the second frame! Why is this so? The dialog belongs to the original
frame.
>> The second frame belongs to nothing but does close automatically when
the
>> first frame is closed.
>>
>> Thanks,
>> Kent
>>
>
>
-
Re: JFrame / JDialog issue
Hi Kent,
i tried a few things out... but to no avail, the dialog blocks every
single window i got.
My guess is that we are talking about a single application here, and a
dialog blocks access to the whole application it is generated from when
modal.
If itīs possible post your source or at least the chunck of code that
handles frame and dialog creation here.
Laters
Volker
Kent wrote:
> Hi Volker,
>
> Thanks for your reply. See my further comments / questions below.
>
> Kent
>
> Volker Held <vheld@gwdg.de> wrote:
>
>>Hi Kent,
>>
>>itīs a normal "limitation" to frames, they are not modal, which means
>>they donīt block other parts of the application until they have been closed.
>>
>
> Agreed.
>
>
>>Dialogs on the other hand are meant to require user action ( like
>>clicking on the okay button ) and thus halt all access to the calling
>>window / frame until the dialog is closed.
>>
>
> Also agreed. The problem is my dialog (opened from frame 1) blocks access
> to the second frame! Why is this? I have set my dialog owner to frame 1 via
> the JDialog constructor.
>
> Further to this I tried opening a JDialog from frame 2 and this blocked access
> to frame 1! What the...?
>
>
>>As far as i know it is not possible by standard means to make a JFrame
>>modal ( and let it act like a dialog that way ).
>>
>>Your second frame closes automatically when you close the first frame,
>>because you most likely call the second from the first - that means the
>>
>
>>first or "main" frame holds reference to the "child" ( just try to
>>picture it that way, for the second frame is actually no child in java
>>language terms ) frame.
>>
>
> Yes, I agree - that is exactly what is happening.
>
>
>>When you close ( destroy ) the first window the reference to the second
>>
>
>>frame is lost and it is cleaned up by garbage collection.
>>
>>Hope that helps
>>
>>Volker
>>
>>Kent wrote:
>>
>>>Hi All,
>>>
>>>I have an application which initially runs in one JFrame. When the user
>>>
> selects
>
>>>a Help menu item another JFrame opens and the user can switch between
>>>
> both
>
>>>frames with no problems.
>>>
>>>However, when I open a JDialog in the original frame you cannot navigate
>>>in the second frame! Why is this so? The dialog belongs to the original
>>>
> frame.
>
>>>The second frame belongs to nothing but does close automatically when
>>>
> the
>
>>>first frame is closed.
>>>
>>>Thanks,
>>>Kent
>>>
>>>
>>
>
-
Re: JFrame / JDialog issue
Hi again Kent,
i searched around a bit and in the current versions of Swing / Java
Dialogs are indeed application modal - looks like this is restricted,
because otherwise the platform indepence could be compromised in some
programs...
But what confuses me a bit is that you said, when you call the dialog
from frame 2 it blocks frame 1 - but i was wondering - is frame 2
blocked as well or not?
Cheers
Volker
Volker Held wrote:
> Hi Kent,
>
> i tried a few things out... but to no avail, the dialog blocks every
> single window i got.
> My guess is that we are talking about a single application here, and a
> dialog blocks access to the whole application it is generated from when
> modal.
>
> If itīs possible post your source or at least the chunck of code that
> handles frame and dialog creation here.
>
> Laters
>
> Volker
>
> Kent wrote:
>
>> Hi Volker,
>>
>> Thanks for your reply. See my further comments / questions below.
>>
>> Kent
>>
>> Volker Held <vheld@gwdg.de> wrote:
>>
>>> Hi Kent,
>>>
>>> itīs a normal "limitation" to frames, they are not modal, which means
>>> they donīt block other parts of the application until they have been
>>> closed.
>>>
>>
>> Agreed.
>>
>>
>>> Dialogs on the other hand are meant to require user action ( like
>>> clicking on the okay button ) and thus halt all access to the calling
>>> window / frame until the dialog is closed.
>>>
>>
>> Also agreed. The problem is my dialog (opened from frame 1) blocks access
>> to the second frame! Why is this? I have set my dialog owner to frame
>> 1 via
>> the JDialog constructor.
>>
>> Further to this I tried opening a JDialog from frame 2 and this
>> blocked access
>> to frame 1! What the...?
>>
>>
>>> As far as i know it is not possible by standard means to make a
>>> JFrame modal ( and let it act like a dialog that way ).
>>>
>>> Your second frame closes automatically when you close the first
>>> frame, because you most likely call the second from the first - that
>>> means the
>>>
>>
>>> first or "main" frame holds reference to the "child" ( just try to
>>> picture it that way, for the second frame is actually no child in
>>> java language terms ) frame.
>>>
>>
>> Yes, I agree - that is exactly what is happening.
>>
>>
>>> When you close ( destroy ) the first window the reference to the second
>>>
>>
>>> frame is lost and it is cleaned up by garbage collection.
>>>
>>> Hope that helps
>>>
>>> Volker
>>>
>>> Kent wrote:
>>>
>>>> Hi All,
>>>>
>>>> I have an application which initially runs in one JFrame. When the user
>>>>
>> selects
>>
>>>> a Help menu item another JFrame opens and the user can switch between
>>>>
>> both
>>
>>>> frames with no problems.
>>>>
>>>> However, when I open a JDialog in the original frame you cannot
>>>> navigate
>>>> in the second frame! Why is this so? The dialog belongs to the original
>>>>
>> frame.
>>
>>>> The second frame belongs to nothing but does close automatically when
>>>>
>> the
>>
>>>> first frame is closed.
>>>>
>>>> Thanks,
>>>> Kent
>>>>
>>>>
>>>
>>
>
>
-
Re: JFrame / JDialog issue
Hi Volker,
Yep, I had a closer look at Swing doco and discovered the same thing - it
is an intended limitation. Posting my code isn't really a viable option here
so I'll instead give you some pseudo-code:
//Frame 1
1] User requests help?
1.1] Y, open Frame 2 (new JFrame())
2] User requests application options?
2.1] Y, open options dialog (new JDialog(Frame 1))
//Frame 2
1] Nothing interesting :-)
In answer to your other question regarding opening the dialog from the second
frame - yes, both frames are blocked.
I get the feeling I'm just going to have to live with this. Interestingly,
I can still interact with the second frame when the dialog is open in the
first. So I can still load help files in the second frame whilst there is
a dialog open in the first. To interact with the second frame, however, the
user has to go back and close the dialog.
Regards,
Kent
Volker Held <vheld@gwdg.de> wrote:
>Hi again Kent,
>
>i searched around a bit and in the current versions of Swing / Java
>Dialogs are indeed application modal - looks like this is restricted,
>because otherwise the platform indepence could be compromised in some
>programs...
>
>But what confuses me a bit is that you said, when you call the dialog
>from frame 2 it blocks frame 1 - but i was wondering - is frame 2
>blocked as well or not?
>
>Cheers
>
>Volker
>
>Volker Held wrote:
>> Hi Kent,
>>
>> i tried a few things out... but to no avail, the dialog blocks every
>> single window i got.
>> My guess is that we are talking about a single application here, and a
>> dialog blocks access to the whole application it is generated from when
>> modal.
>>
>> If itīs possible post your source or at least the chunck of code that
>> handles frame and dialog creation here.
>>
>> Laters
>>
>> Volker
>>
>> Kent wrote:
>>
>>> Hi Volker,
>>>
>>> Thanks for your reply. See my further comments / questions below.
>>>
>>> Kent
>>>
>>> Volker Held <vheld@gwdg.de> wrote:
>>>
>>>> Hi Kent,
>>>>
>>>> itīs a normal "limitation" to frames, they are not modal, which means
>>>> they donīt block other parts of the application until they have been
>>>> closed.
>>>>
>>>
>>> Agreed.
>>>
>>>
>>>> Dialogs on the other hand are meant to require user action ( like
>>>> clicking on the okay button ) and thus halt all access to the calling
>>>> window / frame until the dialog is closed.
>>>>
>>>
>>> Also agreed. The problem is my dialog (opened from frame 1) blocks access
>>> to the second frame! Why is this? I have set my dialog owner to frame
>>> 1 via
>>> the JDialog constructor.
>>>
>>> Further to this I tried opening a JDialog from frame 2 and this
>>> blocked access
>>> to frame 1! What the...?
>>>
>>>
>>>> As far as i know it is not possible by standard means to make a
>>>> JFrame modal ( and let it act like a dialog that way ).
>>>>
>>>> Your second frame closes automatically when you close the first
>>>> frame, because you most likely call the second from the first - that
>>>> means the
>>>>
>>>
>>>> first or "main" frame holds reference to the "child" ( just try to
>>>> picture it that way, for the second frame is actually no child in
>>>> java language terms ) frame.
>>>>
>>>
>>> Yes, I agree - that is exactly what is happening.
>>>
>>>
>>>> When you close ( destroy ) the first window the reference to the second
>>>>
>>>
>>>> frame is lost and it is cleaned up by garbage collection.
>>>>
>>>> Hope that helps
>>>>
>>>> Volker
>>>>
>>>> Kent wrote:
>>>>
>>>>> Hi All,
>>>>>
>>>>> I have an application which initially runs in one JFrame. When the
user
>>>>>
>>> selects
>>>
>>>>> a Help menu item another JFrame opens and the user can switch between
>>>>>
>>> both
>>>
>>>>> frames with no problems.
>>>>>
>>>>> However, when I open a JDialog in the original frame you cannot
>>>>> navigate
>>>>> in the second frame! Why is this so? The dialog belongs to the original
>>>>>
>>> frame.
>>>
>>>>> The second frame belongs to nothing but does close automatically when
>>>>>
>>> the
>>>
>>>>> first frame is closed.
>>>>>
>>>>> Thanks,
>>>>> Kent
>>>>>
>>>>>
>>>>
>>>
>>
>>
>
>
-
Re: JFrame / JDialog issue
Hi,
It seems you have set the JDialog to Modal using setModal(boolean). Once
a Modal JDialog is visible it blocks all user events for other windows. Swing
events are dispatched on single thread i.e. Swing is Single Threaded. That
is why once the Modal JDialog captures all events you cannot do anything
in that particular JVM itself.
You may try using Non-Modal JDialog if it suits your requirement. As
of JDK 1.3 Non-Modal JDialog allow user to do something in other windows
but it stays on top always.
Cheers,Swapnil
-
Re: JFrame / JDialog issue
Hi Kent, Hi Swapnil,
@ Swapney:
I think kentīs idea was that he blocks one frame but still has access to
the other - problem is, you have make a modal dialog - i think non-modal
wouldnīt suit his needs....
@ Kent:
Iīm using 1.3.1_02 - maybe this issue is adressed in 1.4 but i cannot
tell yet. ( If you have any knowledge about that Swapnil, please tell us. )
One way to simulate window modal dialogs might be to set all components
on the "calling" window/frame to enabled = false and when the dialog
closes you have to re-enabled them...
Dunno if thatīs a reasonable idea, but it may be worth a try....
Volker
Swapnil wrote:
> Hi,
>
> It seems you have set the JDialog to Modal using setModal(boolean). Once
> a Modal JDialog is visible it blocks all user events for other windows. Swing
> events are dispatched on single thread i.e. Swing is Single Threaded. That
> is why once the Modal JDialog captures all events you cannot do anything
> in that particular JVM itself.
> You may try using Non-Modal JDialog if it suits your requirement. As
> of JDK 1.3 Non-Modal JDialog allow user to do something in other windows
> but it stays on top always.
>
> Cheers,Swapnil
>
-
Re: JFrame / JDialog issue
Hi Volker / Swapnil,
No, a non-modal dialog wouldn't suit my needs. I really don't want the user
to interact with the frame that opens the dialog - just the frame that doesn't.
Also Volker, your suggestion of disabling controls in the opening frame would
be feasible for a smaller application but unfortunately my app is just too
big - dialogs being opened from dialogs etc.
By the sounds of it it's simply not possible (single thread for UI). So I
guess my options are:
1. live with it
2. open second frame in a second process
Option 1 is probably what I'll go with but I'm also interested in option
2. My question would be how I can get the two processes to communicate with
each other.
I know I can start the second process via one of the Runtime.exec() methods
but how can I easily communicate between processes? Using the input / output
streams of the processes somehow?
Thanks,
Kent
Volker Held <vheld@gwdg.de> wrote:
>Hi Kent, Hi Swapnil,
>
>@ Swapney:
>I think kentīs idea was that he blocks one frame but still has access to
>the other - problem is, you have make a modal dialog - i think non-modal
>wouldnīt suit his needs....
>
>@ Kent:
>Iīm using 1.3.1_02 - maybe this issue is adressed in 1.4 but i cannot
>tell yet. ( If you have any knowledge about that Swapnil, please tell us.
)
>One way to simulate window modal dialogs might be to set all components
>on the "calling" window/frame to enabled = false and when the dialog
>closes you have to re-enabled them...
>Dunno if thatīs a reasonable idea, but it may be worth a try....
>
>Volker
>
>Swapnil wrote:
>> Hi,
>>
>> It seems you have set the JDialog to Modal using setModal(boolean). Once
>> a Modal JDialog is visible it blocks all user events for other windows.
Swing
>> events are dispatched on single thread i.e. Swing is Single Threaded.
That
>> is why once the Modal JDialog captures all events you cannot do anything
>> in that particular JVM itself.
>> You may try using Non-Modal JDialog if it suits your requirement.
As
>> of JDK 1.3 Non-Modal JDialog allow user to do something in other windows
>> but it stays on top always.
>>
>> Cheers,Swapnil
>>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks