我的代码如下,我正在尝试接收m_rows,这是一个数组。看起来它保持空白,我的框架保持空白。我可以看到班级收到了这个活动。我认为我的班级表工作正常。在从侦听器接收m_rows并将其传递给TableModel(m_rows)之间的代码中,您是否看到任何明显错误的内容?
由于
class Frame extends JFrame implements FlowListener {
private List<Candle> m_rows = new ArrayList<Candle>();
public Frame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Ma premiere fenetre");
setBounds(50, 100, 1000, 800);
Container conteneur = new JPanel();
TableModel tableModel = new TableModel(m_rows);
JTable table = new JTable(tableModel);
JPanel tablePanel = new JPanel();
tablePanel.add(table);
conteneur.setLayout(new GridLayout(2, 1));
conteneur.add(tablePanel);
this.add(conteneur);
this.setVisible(true);
}
@Override
public void updateOnFlow(List<Candle> newFlow) {
m_rows = newFlow;
this.repaint();
}
}
答案 0 :(得分:1)
我认为问题在于为m_row
分配内容对TableModel
没有影响。试试这个:
class Frame extends JFrame implements FlowListener {
private JTable table;
...
public Frame() {
...
TableModel tableModel = new TableModel(m_rows); // Did you mean DefaultTableModel?
table = new JTable(tableModel);
...
}
@Override
public void updateOnFlow(List<Candle> newFlow) {
m_rows = newFlow;
TableModel tableModel = new TableModel(m_rows);
table.setModel(tableModel);
this.repaint();
}
}