Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTable with DefaultTableModel not showing?

843806Aug 29 2008 — edited Aug 29 2008
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()	
	
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 26 2008
Added on Aug 29 2008
2 comments
977 views