1

the application I am working on uses Netbeans modules, the problem I am having is that I have a Jtable in one module that I would like to update its contents from another module.

The module with the table in it acts as a data panel, where information can be selected and then plotted as graph using JfreeChart, the next modules handles the creation of the chart, when the data is being put into series to be plotted I am doing some analysis, simple stuff average error, STD etc but would like said information to be displayed in the Jtable which is part of the first module i spoke of.

So my question is, is there any way to access this Jtable from another Netbeans module and if so what is the best way to go about doing this ?

Thanks in advance.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Lewis
  • 70
  • 8

1 Answers1

1

Add your chosen dataset as a TableModelListener to your TableModel. In the event handler, update the dataset as indicated by the TableModelEvent in order to fireDatasetChanged() implicitly. The chart will update automatically.

Example dataset:

class MyDataset extends XYSeriesCollection implements TableModelListener {

    @Override
    public void tableChanged(TableModelEvent e) {
        // update dataset to fireDatasetChanged();
    }
}

Example usage:

MyDataset dataset = new MyDataset();
JTable table = new JTable(…);
table.getModel().addTableModelListener(dataset);
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • thanks for your answer, first of all I don't want to pass the dataset used for the chart to the table, but the data calculated for the analysis. Also will the idea suggested work across different netbeans modules? That is where I'm having the most trouble - actually being able to access the table from another module – Lewis Aug 01 '13 at 07:56
  • You'd be loosely coupling the models by adding one as a listener to the other; the approach is preferred irrespective of IDE; don't let a GUI editor dictate you design; use the approach shown [here](http://stackoverflow.com/a/2561540/230513). – trashgod Aug 01 '13 at 11:02