Click to See Complete Forum and Search --> : frame.toFront(), but not all the way?
pwnage101
August 11th, 2009, 08:10 PM
i want primary frame A to come to focus when the user clicks on it, but i also want secondary frame B to come up just behind it.
from within frame A, I write:
public void windowGainedFocus(WindowEvent e) {
if(windowB.getState() == Frame.ICONIFIED) windowB.setState(Frame.NORMAL);
windowB.toFront();
}
but i dont want window B in focus, i just want it visible. how can i do this?
thanks
dlorde
August 12th, 2009, 06:32 AM
Have you tried following the call to windowB.toFront() with a call to this.toFront(), so windowB comes to the front then the current window comes in front of it? You may have to make the second call in a SwingUtilities.invokeLater() block to ensure that windowB has come to the front before you bring the current window to the front.
Vague and nebulous is the beginning of all things, but not their end...
K. Gibran
pwnage101
August 12th, 2009, 03:01 PM
yes I have, but once that is initiated, it will repetitively call this method and the windows will just flicker in a never-ending sequence
dlorde
August 12th, 2009, 05:57 PM
Yes... I see the problem. You could get around it by setting a boolean member variable true when you call this.toFront(), and checking it at the start of the windowGainedFocus method - if it's true, the method has just been called, so you don't need to do anything but set the boolean back to false. If it's false, then continue with the method, setting B to front, then A to front and set the boolean true to stop the repeating. Something like this:boolean atFront = false;
...
public void windowGainedFocus(WindowEvent e) {
if (atFront) {
atFront = false;
return;
}
if(windowB.getState() == Frame.ICONIFIED) {
windowB.setState(Frame.NORMAL);
}
windowB.toFront();
atFront = true;
this.toFront();
}It's a bit clunky, but should work. I can't think of a better way off the top of my head...
The person who says it cannot be done should not interrupt the person doing it...
Chinese proverb
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.