gpt4 book ai didi

java - JFrame 在收到事件后不绘制

转载 作者:行者123 更新时间:2023-11-30 07:08:47 26 4
gpt4 key购买 nike

我的代码如下,我正在尝试接收 m_rows,它是一个数组。看起来它仍然是空的,我的框架仍然是空白的。我可以看到类(class)已经收到了该事件。我认为我的类(class)表工作正常。您是否发现下面的代码在从监听器接收 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();

}

}

最佳答案

我认为问题在于将某些内容分配给m_rowTableModel没有影响。试试这个:

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();
}
}

关于java - JFrame 在收到事件后不绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39573708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com