CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    2

    frame.toFront(), but not all the way?

    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

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: frame.toFront(), but not all the way?

    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
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Aug 2009
    Posts
    2

    Re: frame.toFront(), but not all the way?

    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

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: frame.toFront(), but not all the way?

    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:
    Code:
    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
    Last edited by dlorde; August 12th, 2009 at 06:01 PM.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured