追加JTextArea&的invokeLater()

时间:2011-10-13 06:16:25

标签: java swing jtextarea

我需要一些帮助,

我基本上有menuVIP.java和vipKeyword.java。

这是menuVIP.java

if (source == enter2) {
            Thread blah = new Thread() {
                String keyword = keyfield.getText();
                public void run() {
                    final String result;
                    vipKeyword vipK = new vipKeyword();
                    result = vipK.keyword(keyword);
                }

            };

            blah.start();

这是vipKeyword.java

public class vipKeyword {

public String keyword(String keyword) {
    menuVIP vip = new menuVIP();

    String password;
    String tbl;
    String Final = null;
    int dot;
    try {

        databaseConnection dbC = new databaseConnection();
        dbC.connection();

        PreparedStatement prep2 = dbC.conn.prepareStatement("SELECT * "
                + "FROM Vip_tbl");
        ResultSet rs = prep2.executeQuery();

        while(rs.next()) {
            cellnumber = rs.getString(1);
            try {
            final String cell;
            cell = cellnumber;
                    SwingUtilities.invokeLater(new Runnable() {
                        menuVIP vip = new menuVIP();
                        public void run() {
                            vip.ta.append(cell + "\n");
                            vip.ta.repaint();
                        }

                    });
return keyword;
}

我需要知道的是如何在SwingUtilities.invokelater()中从我的vipKeyword“追加”Jtextarea?

注意:ta = JTextArea

1 个答案:

答案 0 :(得分:1)

public String keyword(String keyword) {
     final menuVIP vip = new menuVIP(); // mark it as final

...

 SwingUtilities.invokeLater(new Runnable() { 
    //menuVIP vip = new menuVIP();   // comment it