Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何“刷新”表格,以便显示具有不同数据的同一表格?_Java_Swing - Fatal编程技术网

Java 如何“刷新”表格,以便显示具有不同数据的同一表格?

Java 如何“刷新”表格,以便显示具有不同数据的同一表格?,java,swing,Java,Swing,如何刷新表格,以便显示具有不同数据的同一表格 String columnNames[] = {"First Name", "Last Name", "Phone Number", "E-mail"}; JTable contactTable = new JTable(data, columnNames); jScrollPane = new JScrollPane(contactTable,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScr

如何刷新表格,以便显示具有不同数据的同一表格

String columnNames[] = {"First Name", "Last Name", "Phone Number", "E-mail"};
    JTable contactTable = new JTable(data, columnNames);
    jScrollPane = new JScrollPane(contactTable,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

您的数据保存在哪里

我把它保存在一个文本文件中,并用这种方式刷新我的数据,但每次都需要一个按钮来刷新

这是我的密码

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // Refresh Button

        try {
            for (int r = 0; r < 100; r++) { //initializing row
                for (int c = 0; c < 4; c++) { //initializing column
                    jTable1.setValueAt(null, r, c);
                }
            }

            BufferedReader rdfile = new BufferedReader(new FileReader("items.txt"));

            String[] item = new String[100];
            String[] temp;

            int x = 0;  //read item
            while ((item[x] = rdfile.readLine()) != null) {
                temp = item[x].split("\t");
                jTable1.setValueAt((1000 + x + 1), x, 0);
                for (int j = 1; j < 4; j++) {
                    jTable1.setValueAt(temp[j - 1], x, j);
                }

                x++;
            }
            rdfile.close();

        } catch (IOException e) {
        }

    }

更改表格模型。有关更多详细信息,请参阅刷新的定义?以下是@MadProgrammer的答案。。。可能重复的