I hope this is SSCE...
I'm using a defaultTableModel, but I cannot get the Table to show.
When I just simply put the vectors straight into the table, without using the DefaultTableModel it worked.
This is the code I have now, the table doesn't show at all?
I actually couldn't get this example to compile, as it only contains snippets of the code. The real code compiles and runs, but the table just doesn't show. I guess it's all part of the same problem.
If someone could help me with where I've gone wrong in the usage of the DefaultTableModel, it would be greatly appreciated.
import java.util.Vector;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.event.*;
public class FutureTable extends JTable implements TableModelListener {
Vector colnames = new Vector();
Vector inne = new Vector();
TableModel model;
JTable table = new JTable();
public FutureTable(){
//vector colnames
colnames.addElement("Date");
//vector inne
inne.addElement("example")
//Adds inne and colnames to the TableModel model
model = new DefaultTableModel(inne, colnames);
//sets Table to TableModel model
table.setModel(model);
//adds a listener to the table
table.getModel().addTableModelListener(this);
}
}
import javax.swing.*;
import java.awt.*;
import java.util.Vector;
public class FutureTableHolder extends JPanel {
Vector inne = new Vector();
JScrollPane scrollPane;
FutureTable theTable = new FutureTable();
public FutureTableHolder() {
//Sets the layout to gridlayout so that the table will fill the panel.
setLayout(new GridLayout(1,0));
scrollPane= new JScrollPane(theTable);//ScrollPane
add(scrollPane);
}//Ends FutureTableHolder()