JTextArea不会附加/ setText

时间:2012-03-06 21:09:10

标签: java swing jtextarea

为什么第17行不会立即更新? JFrame和JDialogs并不特别。我想在第二个JDialog被处理后更新第一个JDialog的textArea。当点击JButton时,模态JDialog调用它的dispose方法。

package javaapplication1;

public class NewJFrame extends javax.swing.JFrame
{

public NewJFrame()
{
    initComponents();
    boolean isModal = true;
    NewJDialog jd = new NewJDialog(this, !isModal);
    jd.setVisible(true);
    jd.ta.setText("1\n"); //good
    NewJDialog1 d1 = new NewJDialog1(this,isModal);
    jd.ta.append("2\n"); //good
    d1.setVisible(true);
    System.out.println("3"); //prints at this instace
    jd.ta.append("3\n"); //doesn't display at this instance
    System.out.println("3"); //prints at this instace
    System.out.println(); //debug breakpoint                  
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 400, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 300, Short.MAX_VALUE)
    );

    pack();
}// </editor-fold>                        

public static void main(String args[])
{
    java.awt.EventQueue.invokeLater(new Runnable()
    {
        public void run()
        {
            new NewJFrame().setVisible(true);
        }
    });
}
// Variables declaration - do not modify                     
// End of variables declaration                   
}

0 个答案:

没有答案