Iam creating multiple frames from one Main Frame.<br>!_NEWLINE_!How can i identify a currently active frame from code in Main Frame
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jamal_Mohideen
Posted On:   Thursday, May 30, 2002 03:48 AM

Iam creating multiple frames from one Main Frame.

How can i identify a currently active frame from code in Main Frame , Iam using Thread to do this, but it is not giving me the Active Frame.



I used hasFocus() function.... pls help me to solve this problem


Jamal

Mail me the Answer

Re: Iam creating multiple frames from one Main Frame.<br>!_NEWLINE_!How can i identify a currently active frame from code in Main Frame

Posted By:   Mike_Smith  
Posted On:   Thursday, May 30, 2002 06:47 AM

I think the problem may be that hasFocus() works on which Component has Keyboard focus (rather than at Container level). If a component in your Frame has focus, then the window won't.


What you need to do is override the hasFocus() method in your JFrame subclass to something like





public boolean hasFocus() {
boolean toReturn = false;
for ( int i=0; i < getComponentCount(); i++ ) {
if ( getComponent( i ).hasFocus() ) {
toReturn = true;
break;
}

return toReturn;
}


This will look through all components in your JFrame to see if they have focus. You will then most likely have to have custom JPanel for your content pane to do the same.

Another way would be to set up a FocusAdapter on your frame to register with your main frame which window has focus.

Hope that helps


Mike
About | Sitemap | Contact