java - Update a JTable data completely each time I perform a function -


Can you help me make this piece of code? I have created a table that changes its data every time the function is triggered. Code is made up of three sections.

Table model

  Public class MyTableModel AbstractTableModel {Personal Stable Last Long Serial VersionUID = 1L; Private Static String [] Header = {"A", "B", "C", "So On"}; Public MyTableModel () {} Recording List Data = New Recording List (); Public Zero addData (in the recording list data) {data = data; This.fireTableDataChanged (); } @ Override Public Ent column column () {Return header. Long; // Length; } @ Override Public Intervount () {return data.size (); } @ Override public string getColumnName (ant colle) {return header [cola]; } @ Override public string getValueAt (int row, int col) {object [] row selected = data .getRecordingRow (line); Return row selected [cola] .toString (); }}  

JTable

  Public class DynamicTable JTable implements TableModelListener {/ ** * * / MyTableModel model; Private static last long serial VERSIONUID = 1 L; Public DynamicTable () {model = new MyTableModel (); Start (); } Zero start () {setFillsViewportHeight (true); SetModel (model); . GetModel () addTableModelListener (this); SetForeground (Color.BLACK); SetShowGrid (true); SetShowVerticalLines (true); SetBackground (Color.WHITE); Try {// 1.6+ setAutoCreateRowSorter (true); } Hold (Exception Continuity Noise) {}} By changing the Public Zero Table (Tablemodel Event E) {Tablemodel Pneumodel = (Tablemodel) e.getSource (); Model = (MyTableModel) newModel; SetModel (model); // do something with the data ...}}  

Finally I have implemented a third class that has to update tables and models

this Clearly one is a really wrong approach and I hereby understand what I am trying to achieve:

  recording list recording list = cr.getResultQuery (); MyTableModel newModel = New MyTableModel (); NewModel.addData (recordingList); Tablemodel event event = new table event event (new modell); Dynamic Tables DT = New DynamicTable (); Dt.tableChanged (event);  

You can create your new MyTableModel object, and then just set it up Currently the JTB model is displayed . Bus. The key is currently referencing the JTable display that is displayed, and this will depend on your code structure and the references you give.

I'm not sure what you're trying to achieve with TableModelEvent, but it's not needed.

If this answer is insufficient, you will need to create and post it so that we can understand your problem better.


Comments