jTable row count VS model row count

后端 未结 2 1334
别跟我提以往
别跟我提以往 2021-01-28 02:42

I have a jTable which loads data from a DB query This load produces 32 results, thus 32 rows in the TableModel With myTable.getRowCount()

2条回答
  •  无人共我
    2021-01-28 03:07

    Can you post a verifiable code of yours? because i tried with the following code and the model changed without any issues.

      public static void main(String[] args) throws InterruptedException {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            DefaultTableModel model = new DefaultTableModel(
                    new Object[][] { { "some", "text" }, { "any", "text" },
                            { "even", "more" }, { "text", "strings" },
                            { "and", "other" }, { "text", "values" } },
                    new Object[] { "Column 1", "Column 2" });
            String[] columnNames= {null};
            DefaultTableModel model1 = new DefaultTableModel(null,columnNames);
            model1.setRowCount(0);
    
    
            JTable table = new JTable(model);
            JScrollPane scrollPane = new JScrollPane(table);
            frame.add(scrollPane, BorderLayout.CENTER);
            frame.setSize(300, 150);
            frame.setVisible(true);
            Thread.sleep(5000);
            table.setModel(model1);
        }
    

提交回复
热议问题