1

I have my code below, I am trying to receive m_rows which is an array. It looks like it stays empty and my frame stays blank. I can see the class has received the event. I think my class Table works ok. Do you see anything obviously wrong in the code below between the receipt of m_rows from the listener and passing it to TableModel(m_rows)?

Thanks

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

    }

}
  • Did you also try `validate()`? http://stackoverflow.com/questions/1097366/java-swing-revalidate-vs-repaint – Sentry Sep 19 '16 at 13:03
  • Also, did you check that `updateOnFlow` is really called? Where do you register the `Frame` instance as `FlowListener`? – Sentry Sep 19 '16 at 13:07
  • yes I tried validate and not working. updateOnFlow is called, I get the results on a system.out.println inside updateOnFlow, Frame is registered in another class. –  Sep 19 '16 at 13:25

1 Answers1

1

I think the problem is that assigning something to m_row has no effect on the TableModel. Try this:

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();
    }
}
Sentry
  • 4,102
  • 2
  • 30
  • 38