Results 1 to 5 of 5
  1. #1
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

    Default update contentpane and jOptionPane problem

    hello every one i have a simple problem here.
    i want to update first the contentPane of JFrame before displaying JOptionPane but some time JOptionPane display first even contentPane doest not update i dont know whats is the problem here.

    here my code.

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    try{
    setContentPane(jPanel3);
    SwingUtilities.updateComponentTreeUI(this);
    logstart = true;
    boolean connection = false;
    if(logstart == true){
    try{
    chkmembers chk = new chkmembers();
    String bolstr = chk.chemembers(jTextField1.getText());
    if(bolstr.equals("true")){
    JOptionPane.showMessageDialog(null,"True");
    }else{
    JOptionPane.showMessageDialog(null,"False");
    setContentPane(jDialog1);
    connection = true;
    }
    }catch(Exception e){
    setContentPane(jPanel1);
    if(connection == true){
    JOptionPane.showMessageDialog(null,"Internet Connecton Error.");
    }connection = false;
    }
    }
    }catch(Exception e){}
    }

  2. #2
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Post

    I suggest using invokeAndWait() api of SwingUtilities to perform these kinds of updates on GUI.

    This api will ensure that your program waits, till the time your

    SwingUtilities.updateComponentTreeUI(this);

    is performed.

  3. #3
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

    Default

    How to do that? can you post a sample?

  4. #4
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    Quote Originally Posted by lovelesh View Post
    I suggest using invokeAndWait() api of SwingUtilities to perform these kinds of updates on GUI.

    This api will ensure that your program waits, till the time your

    SwingUtilities.updateComponentTreeUI(this);

    is performed.
    I suspect that this advice, while completely correct and commendable, is way over the OP's head. Perhaps the problem can be solved (for now) by calling validate() on the component after the contents are changed but before the option pane is popped.

  5. #5
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

    Default

    can you post a simple sample using invokeAndWait() and validate() inside jbutton? plss . help i need it.

Similar Threads

  1. contentpane
    By marodia in forum AWT / Swing
    Replies: 7
    Last Post: 08-27-2009, 07:30 AM
  2. Rootpane,ContentPane,LayeredPane
    By makpandian in forum AWT / Swing
    Replies: 2
    Last Post: 01-30-2009, 11:22 PM
  3. JOptionPane problem
    By MomenT in forum New To Java
    Replies: 22
    Last Post: 10-02-2008, 05:56 PM
  4. adding the Java Console to a ContentPane
    By naipulb in forum New To Java
    Replies: 1
    Last Post: 06-10-2008, 08:51 AM
  5. Problem with JOptionPane.showInputDialog()
    By romina in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:33 AM

Posting Permissions

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