I'm trying to use a JTable to display a list of files and some information about them. actually at this point the fact that they're files doesn't matter that much.
I'm trying to display information via a JTable. however the only way i know how to get data to the JTable is through the constructor. So how would i append rows to or preferably completely replace the information in a JTable using a change listener?
here's where i've been stumped. I have many other classes which i hope are not relevant to this issue, unless my code should work... which i doubt. the JARmanager is another class in my program which manages a list of files and the getTable method returns a vector of object[]'s which contain a single string. the system.out line is for testing and the vector is being populated correctly.
Code:
import java.awt.BorderLayout;
import javax.swing.table.DefaultTableModel;
import javax.swing.event.*; //ChangeEvent, ChangeListener,
import javax.swing.*; //JPanel, JScrollPane, JTable, DefaultListSelectionModel,
import java.util.Vector;
public class TableView extends JPanel implements ChangeListener {
Vector<String> columnNames = new Vector<String>();
Vector data;
JTable table;
JScrollPane scroll;
JARmanager jman;
public TableView(JARmanager man) {
columnNames.add("Name");
columnNames.add("Type");
data = man.getTable();
jman = man;
table = new JTable(data, columnNames);
table.setFillsViewportHeight(true);
table.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
table.setColumnSelectionAllowed(false);
scroll = new JScrollPane(table);
this.setLayout(new BorderLayout());
this.add(scroll, BorderLayout.CENTER);
}
public void stateChanged(ChangeEvent e) {
data = jman.getTable();
System.out.println(data);
}
} does anyone know what to do?
does anyone understand my question?