The Artima Developer Community
Sponsored Link

Java Answers Forum
Focus issues??

7 replies on 1 page. Most recent reply: Sep 21, 2005 10:13 PM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 7 replies on 1 page
Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Focus issues?? Posted: Sep 7, 2005 6:46 AM
Reply to this message Reply
Advertisement
I have a JOption Pane which is being called up from
various Components (in the event that there is an
error etc).

Signature:

public static void a_message(Component parentCmp, String mess)

I want to do something to the effect of:
    if(parentComp.hasFocus()){
       //  execute Something equivalent to the OS
       //  function Alt+Tab
    }

Please assist on how to go about those commented sections.

Spike


Jeff Thomson

Posts: 14
Nickname: thomson
Registered: Sep, 2005

Re: Focus issues?? Posted: Sep 15, 2005 7:18 AM
Reply to this message Reply
Hi Kondwani,
I am unable to understand your issue, can you please explain your query with an example?

----------------
Jeff Thomson
http://www.devsquare.com
Online Application Development

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Focus issues?? Posted: Sep 15, 2005 7:30 AM
Reply to this message Reply
Ok I have:

JOptionPane.showConfirmDialog(parentComponent, message, "Confirm", JOptionPane.YES_NO_OPTION);

Unfortunately there are some focus issues I want to ensure
that if this OptionPane has been called or is visible,
focus is never with the parent, e.g:
//  accidentally or otherwise
if(parentComponent.hasFocus()){
    // Alt Tab back to the JOptionPane
}

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Focus issues?? Posted: Sep 15, 2005 10:32 PM
Reply to this message Reply
I still don't understand what's the problem.

The JPotionPane is modal wich means that the window containing the parentComponent can't get the focus back as long as the Dialog is visible.

But if you really wan't to be sure, use this line to get the focus back
this.requestFocus()


Forget that Alt+Tab crap, that's Windows legacy and would never work to 100% since you can never be sure wich Window will get the focus this way.

Also try to play with the FocusLost event.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Focus issues?? Posted: Sep 15, 2005 11:40 PM
Reply to this message Reply
> I still don't understand what's the problem.
>
> The JPotionPane is modal wich means that the window
> containing the parentComponent can't get the focus back as
> long as the Dialog is visible.

I am aware that a JOptionPane is modal but for some reason
it happens less frequently than often, the parentComponent
ends up having focus, and you have to Alt+Tab to get the
OptionPane back. I don't want to skim through 20,000 lines
of code and possibly break the system so I was looking for
a quick fix.

> But if you really wan't to be sure, use this line to get
> the focus back
this.requestFocus()


That won't work, I was looking for more of a hack which
is why I posted this question.

> Forget that Alt+Tab crap, that's Windows legacy and would
> never work to 100% since you can never be sure wich Window
> will get the focus this way.
>

I'm actually behind a Mandrake (Linux) box, so which also
executes the same OS command. I wanted to actually
execute this via Java's Runtime exec method. And call
mandrakes function (possibly this can be written in
native such as C and have Java call it (but that sounds
too complex to me).

Thanks for the suggestions though.

Spike

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Focus issues?? Posted: Sep 19, 2005 11:31 PM
Reply to this message Reply
Ther would be another option.

When the dialog opens, add a focus listener to the parent wich Focus gained method gives the focus to the dialog.

Before you close the dialog remove the listener.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Focus issues?? Posted: Sep 21, 2005 4:28 AM
Reply to this message Reply
Thanks for the suggestion, that din't do the trick
though. I could see that the Focus was in the
back of the JOptionPane yet parent.hasFocus()
returned false. It was very wierd.

Thanks again though.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Focus issues?? Posted: Sep 21, 2005 10:13 PM
Reply to this message Reply
It starts to sound like a bug in the Linux / Java communication.

The parent of a modular dialog should never get the focus.

Your problem happend to me too when I made a dialog modular, but didn't give him a parent. But I don't think you made that mistake.

Flat View: This topic has 7 replies on 1 page
Topic: html text in disabled label Previous Topic   Next Topic Topic: javaxswing message dialog TABLE please help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use