invokeLater

Discussion in 'Java' started by Ike, Feb 1, 2007.

  1. Ike

    Ike Guest

    Can anyone please tell me why my invokeLater in the following code never
    displays the JFrame I am trying to get it to display, and shows no
    exceptions either? I am certain I must have somethign stupid and wrong here.
    Thanks, Ike

    public void putupreconnectnotice(boolean on){
    if(on){
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    connectionLost();
    }
    });
    }else{
    if(waitjframe!=null){
    waitjframe.dispose();
    }
    }
    }

    private void connectionLost(){
    waitjframe = new JFrame("Connection to server lost!");
    waitjframe.setSize(310, 75);
    waitjframepanel=new JPanel();
    waitjframepanel.setPreferredSize(new Dimension(300,60));
    waitjframepanel.setBackground(Color.WHITE);
    waitjframepanel.add(new JLabel("Attempting to reconnect"));
    waitjframe.getContentPane().add(waitjframepanel);
    waitjframe.pack();
    waitjframe.setVisible(false);
    waitjframepanel.grabFocus();
    }
     
    Ike, Feb 1, 2007
    #1
    1. Advertising

  2. In article <YEpwh.19528$>,
    "Ike" <> wrote:

    > Can anyone please tell me why my invokeLater in the following code never
    > displays the JFrame I am trying to get it to display, and shows no
    > exceptions either? I am certain I must have somethign stupid and wrong here.
    > Thanks, Ike
    >
    > public void putupreconnectnotice(boolean on){
    > if(on){
    > javax.swing.SwingUtilities.invokeLater(new Runnable() {
    > public void run() {
    > connectionLost();
    > }
    > });
    > }else{
    > if(waitjframe!=null){
    > waitjframe.dispose();
    > }
    > }
    > }
    >
    > private void connectionLost(){
    > waitjframe = new JFrame("Connection to server lost!");
    > waitjframe.setSize(310, 75);
    > waitjframepanel=new JPanel();
    > waitjframepanel.setPreferredSize(new Dimension(300,60));
    > waitjframepanel.setBackground(Color.WHITE);
    > waitjframepanel.add(new JLabel("Attempting to reconnect"));
    > waitjframe.getContentPane().add(waitjframepanel);
    > waitjframe.pack();
    > waitjframe.setVisible(false);
    > waitjframepanel.grabFocus();
    > }


    Perhaps it's because your connectionLost method specifically calls
    setVisible(false) on the frame?
    --
    Steve W. Jackson
    Montgomery, Alabama
     
    Steve W. Jackson, Feb 1, 2007
    #2
    1. Advertising

  3. Ike schrieb:
    > Can anyone please tell me why my invokeLater in the following code never
    > displays the JFrame I am trying to get it to display, and shows no
    > exceptions either? I am certain I must have somethign stupid and wrong here.
    > Thanks, Ike


    Apart from the possibility of passing false to putupreconnectnotice, I'd
    expect that this

    > waitjframe.setVisible(false);


    isn't what you really want :)

    Bye
    Michael
     
    Michael Rauscher, Feb 1, 2007
    #3
  4. Ike

    Daniel Pitts Guest

    On Feb 1, 9:43 am, "Ike" <> wrote:
    > Can anyone please tell me why my invokeLater in the following code never
    > displays the JFrame I am trying to get it to display, and shows no
    > exceptions either? I am certain I must have somethign stupid and wrong here.
    > Thanks, Ike
    >
    > public void putupreconnectnotice(boolean on){
    > if(on){
    > javax.swing.SwingUtilities.invokeLater(new Runnable() {
    > public void run() {
    > connectionLost();
    > }
    > });
    > }else{
    > if(waitjframe!=null){
    > waitjframe.dispose();
    > }
    > }
    > }
    >
    > private void connectionLost(){
    > waitjframe = new JFrame("Connection to server lost!");
    > waitjframe.setSize(310, 75);
    > waitjframepanel=new JPanel();
    > waitjframepanel.setPreferredSize(new Dimension(300,60));
    > waitjframepanel.setBackground(Color.WHITE);
    > waitjframepanel.add(new JLabel("Attempting to reconnect"));
    > waitjframe.getContentPane().add(waitjframepanel);
    > waitjframe.pack();
    > waitjframe.setVisible(false);
    > waitjframepanel.grabFocus();
    > }


    As others have pointed out
    you might want to setVisible(true) instead of setVisible(false)
     
    Daniel Pitts, Feb 1, 2007
    #4
  5. Ike

    Ike Guest

    Yep....that was it....I just couldn;t see it. Thanks so much guys. -Ike
     
    Ike, Feb 1, 2007
    #5
  6. Ike

    Tom Hawtin Guest

    Ike wrote:
    >
    > public void putupreconnectnotice(boolean on){
    > if(on){
    > javax.swing.SwingUtilities.invokeLater(new Runnable() {
    > public void run() {
    > connectionLost();
    > }
    > });
    > }else{
    > if(waitjframe!=null){
    > waitjframe.dispose();
    > }
    > }
    > }


    Not the problem you were having, but dispose should be run in the EDT as
    well as showing the frame.

    private volatile boolean notice;
    public void setNotice(boolean notice){
    this.notice = notice;
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    if (MyClass.this.notice) {
    connectionLost();
    } else {
    if (noticeFrame != null){
    noticeFrame.dispose();
    }
    }
    }
    });
    }

    Tom Hawtin
     
    Tom Hawtin, Feb 3, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mohit Gupta

    InvokeLater

    Mohit Gupta, Jul 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    2,666
    Mohit Gupta
    Jul 11, 2003
  2. Ike
    Replies:
    2
    Views:
    909
    Harald Hein
    Oct 8, 2003
  3. ***C.Steamer***
    Replies:
    39
    Views:
    1,083
    Thomas G. Marshall
    Oct 29, 2004
  4. Richie
    Replies:
    13
    Views:
    1,985
    Richie
    Oct 29, 2005
  5. Replies:
    1
    Views:
    626
Loading...

Share This Page