JTable(BeanTableModel)未更新/刷新-Java Swing

JTable(BeanTableModel)未更新/刷新-Java Swing,java,swing,jtable,tablemodel,Java,Swing,Jtable,Tablemodel,我有两个面板。一个是用户插入数据,另一个是使用JTable显示结果 我的问题是,当用户按下ok(在我的情况下为apply)按钮时,数据会被计算出来,但不会显示在JTable上,JTable中没有任何变化 对于我的JTable,我使用的是tips4Java()中的Bean表模型 一件奇怪的事情是,如果我在程序启动时将数据(让我们称此数据为“A”)发送到表中,它会显示在表中,如果稍后我尝试更新表,则表不会更新。但是,当我在启动时不向表发送数据,但尝试使用数据“A”更新/发送表时,它不会更新 所以我的

我有两个面板。一个是用户插入数据,另一个是使用
JTable
显示结果

我的问题是,当用户按下ok(在我的情况下为apply)按钮时,数据会被计算出来,但不会显示在
JTable
上,
JTable
中没有任何变化

对于我的
JTable
,我使用的是tips4Java()中的
Bean表模型

一件奇怪的事情是,如果我在程序启动时将数据(让我们称此数据为“A”)发送到表中,它会显示在表中,如果稍后我尝试更新表,则表不会更新。但是,当我在启动时不向表发送数据,但尝试使用数据“A”更新/发送表时,它不会更新

所以我的问题是,
JTable
为什么不显示我发送到的任何数据

这是我的密码:

JButton Listener,用于启动处理并将数据发送到表:

crashForm.setFormListener(new FormListener() {
    @Override
    public void formEvent(OptionsFormEvent oe) {
        String readTable = oe.getReadFromTable();
        int access = oe.getAccess();
        int transition = oe.getTransition();
        boolean smooth = oe.isTrainCrash();
        ArrayList<String> allTrains = new ArrayList<>();
        List crashedTrainList = new ArrayList<>();

        try {
            allTrains = controller.getUniqueTrains(controller.connectServer(), readTable, "trainid");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "An error occured while getting trains data\n"
                    + "Error description: " + ex.getMessage(), "Error",
                    JOptionPane.ERROR_MESSAGE);
        }

        try {
            for (int i = 0; i < allTrains.size(); i++) 
            {
                ArrayList<Train> trainDataList = new ArrayList<>();
                ArrayList<Train> crashedProccessedData = new ArrayList<>();

                String query = "the sql query...";

                trainDataList = controller.getTrainData(controller.connectServer(), readTable, query);

                crashedProccessedData = controller.detectCrash(access, transition, trainDataList);
                crashedTrainList.addAll(crashedProccessedData);

            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "An error occured while detecting a crash.\n"
                    + "Error description: " + ex.getMessage(), "Error",
                    JOptionPane.ERROR_MESSAGE);
        }

        System.out.println("Total crashes detected:" + crashedTrainList.size());
        tablePanel.createTable(Train.class, crashedTrainList, true, false, tableLabels);
        tablePanel.fireTableDataChanged();
    }
});
}
crashForm.setFormListener(新的FormListener(){
@凌驾
公共作废formEvent(选项formEvent oe){
字符串readTable=oe.getReadFromTable();
int access=oe.getAccess();
int transition=oe.getTransition();
布尔平滑=oe.isTrainCrash();
ArrayList allTrains=新的ArrayList();
List crashedTrainList=新建ArrayList();
试一试{
allTrains=controller.getUniqueTrains(controller.connectServer(),可读,“trainid”);
}捕获(例外情况除外){
JOptionPane.showMessageDialog(null,“获取列车数据时出错\n”
+“错误描述:”+ex.getMessage(),“错误”,
JOptionPane.ERROR\u消息);
}
试一试{
对于(int i=0;i
下面是我的tablePanel课程:

    public TablePanel() {
    }
    public void createTable(Class c, List data, boolean toolBarUp, 
            boolean toolBarBottom, ArrayList<String> labelsCheckBox) {

        beanTableModel = new BeanTableModel(c, data);
        columnModel = new XTableColumnModel();
        table = new JTable(beanTableModel);
        table.setColumnModel(columnModel);
        table.createDefaultColumnsFromModel();

        if(toolBarUp == true)
        {
            final JToolBar toolBarTop = new JToolBar();

            // Create the Show ALL
            JButton reset = new JButton("Reset");

            reset.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                for(Component c : toolBarTop.getComponents()){
                    if(c instanceof JCheckBox){
                        JCheckBox checkBox = (JCheckBox) c;
                        checkBox.setSelected(false);
                        columnModel.setAllColumnsVisible();
                    }
                }
                int numberOfColumn = columnModel.getColumnCount();

                for(int aux = 0; aux < numberOfColumn; aux++)
                {
                    int num = columnModel.getColumnCount();
                    TableColumn column = columnModel.getColumnByModelIndex(aux);
                    columnModel.setColumnVisible(column, true);
                }
            }
            });

            toolBarTop.add(reset);

            // Create a JCheckBox for each column
            for(int i = 0; i < labelsCheckBox.size(); i++)
            {
                final int index = i;
                toolBarTop.add(new JCheckBox(new AbstractAction(labelsCheckBox.get(i)) {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        TableColumn column = columnModel.getColumnByModelIndex(index);
                        boolean visible = columnModel.isColumnVisible(column);
                        columnModel.setColumnVisible(column, !visible);
                    }
                }));
            }



            setLayout(new BorderLayout());
            add(toolBarTop, BorderLayout.NORTH);
            add(new JScrollPane(table), BorderLayout.CENTER);
//            add(toolBarDown, BorderLayout.SOUTH);
        }


        final JToolBar toolBarDown = new JToolBar();

        toolBarDown.add(new JButton(new AbstractAction("Save Table") {
            @Override
            public void actionPerformed(ActionEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        }));


    }

    public void createTable(Class c, Class cAncestor) {
        beanTableModel = new BeanTableModel(c, cAncestor);
        table = new JTable(beanTableModel);
        setLayout(new BorderLayout());
        add(new JScrollPane(table), BorderLayout.CENTER);
    }

    public void createTable(Class c, Class cAncestor, List data) {
        beanTableModel = new BeanTableModel(c, cAncestor, data);
        table = new JTable(beanTableModel);
        setLayout(new BorderLayout());
        add(new JScrollPane(table), BorderLayout.CENTER);
        beanTableModel.fireTableDataChanged();
    }

    public void createTable(Class c) {
        beanTableModel = new BeanTableModel(c);
        table = new JTable(beanTableModel);
        setLayout(new BorderLayout());
        add(new JScrollPane(table), BorderLayout.CENTER);
    }

    public void createTable(Class c, List data)
    {
        beanTableModel = new BeanTableModel(c, data);
        table = new JTable(beanTableModel);
        setLayout(new BorderLayout());
        add(new JScrollPane(table), BorderLayout.CENTER);
    }

    //to refresh the table everytime there is an update
    public void fireTableDataChanged()
    {
        beanTableModel.fireTableDataChanged();
    }
public TablePanel(){
}
public void createTable(c类、列表数据、布尔工具栏等),
布尔工具栏(底部,ArrayList标签复选框){
beanTableModel=新的beanTableModel(c,数据);
columnModel=新的XTableColumnModel();
表=新的JTable(beanTableModel);
表.setColumnModel(columnModel);
table.createDefaultColumnsFromModel();
if(toolBarUp==true)
{
最终JToolBar toolbar top=新的JToolBar();
//创建“全部显示”
JButton reset=新JButton(“reset”);
reset.addActionListener(新ActionListener(){
@凌驾
已执行的公共无效操作(操作事件e){
对于(组件c:toolBarTop.getComponents()){
if(JCheckBox的c实例){
JCheckBox checkBox=(JCheckBox)c;
复选框.setSelected(false);
columnModel.setAllColumnsVisible();
}
}
int numberOfColumn=columnModel.getColumnCount();
对于(int aux=0;auxpanel.add(....);
panel.revalidate();
panel.repaint();
table.setModel( newlyCreatedModel );