This discussion is archived
1 Reply Latest reply: Sep 16, 2012 2:53 PM by jduprez RSS

Focus issue across JFrames

962148 Newbie
Currently Being Moderated
Hi,

I have a Swing application which extends JFrame.
I have a JFrame frame1 which invokes another JFrame frame2. frame1 is compiled with JRE 1.6 where as frame2 is compiled with JRE 1.5.
When I try to invoke frame2 from frame1, the focus is shifting to frame1 instead of frame2 though I am doing setVisible(true) on frame2. This behavior is not consistent.
Is this a JRE mismatch problem?
  • 1. Re: Focus issue across JFrames
    jduprez Pro
    Currently Being Moderated
    Hello,
    I don't understand your question :o(
    Or at least, I don't see enough information in it to assume the behavior you witness is not the correct one. So I've skipped your post a few times. Since I see you've had no reply over the week-end, I'll try to help you provide more context so that someone else can help you...

    Let's address it bit by bit:
    When I try to invoke frame2 from frame1
    What does invoke frame2 mean? You invoke a method, not a class. Which method of frame2's class are you invoking, and what do you expect it to perform?
    the focus is shifting to frame1 instead of frame2
    What do you mean by "shifting to frame1"? Is it on frame2 initially? Is it on frame1, but on another widget within frame1?
    though I am doing setVisible(true) on frame2.
    From the Javadoc http://docs.oracle.com/javase/6/docs/api/java/awt/Window.html#setVisible%28boolean%29, if a frame/window is initially invisible, setVisible(true) only displays it, but nothing says it should give it the focus. A second call to setVisible(true) would bring the window/frame to front, i.e. give it the focus.
    This behavior is not consistent.
    Not consistent with what? Do you have other examples where setVisible() gives the focus differently than in this example? Does frame2 call frame1.setVisible(...) and result in a different effect?
    Or do you mean that if you compile both frames' code withj the same JDK version, you obtain a different effect?

    Best regards,

    J

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points