A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
? JTable getColumnName
Geoff Jefferson
Ranch Hand
Joined: Apr 09, 2009
Posts: 102
posted
May 06, 2009 15:12:01
0
I can't figure out why the column names are not showing up on my table.
Here is the code.
package mytablemain; import javax.swing.table.AbstractTableModel; import java.util.List; import java.util.ArrayList; class MyTableModel extends AbstractTableModel { String[] columnNames = {"Testing", "This", "Table", "Model", "Today", "Six"}; protected final List<ItemFile> dataList = new ArrayList<ItemFile>(); public int getRowCount() { return dataList.size(); } public int getColumnCount() { return columnNames.length; } @Override public String getColumnName(int col) { return columnNames[col]; } @Override public Object getValueAt(int row, int col) { ItemFile item = (ItemFile)dataList.get(row); switch(col) { case 0: return item.one; case 1: return item.two; case 2: return item.three; case 3: return item.four; case 4: return item.five; case 5: return item.six; default: assert false; return null; } } public void addItem(ItemFile item){ dataList.add(item); fireTableDataChanged(); } public ItemFile getItem(int a) { return dataList.get(a); } public List<ItemFile> getList(){ return dataList; } public void clearList() { dataList.clear(); fireTableDataChanged(); } } // end class
//snipet private MyTableModel tableModel = new MyTableModel(); JTable table = new JTable(tableModel); table.setPreferredScrollableViewportSize(new Dimension(900, 400)); table.setFillsViewportHeight(true); JScrollPane scrollPane = new JScrollPane(table);
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
I like...
posted
May 07, 2009 01:06:43
0
Geoff, code end tags start with a /, not a \. So it's [/code], not [\code]. I've fixed it for you.
Moving to the Swing forum.
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions
How To Answer Questions
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
May 07, 2009 01:43:56
0
showed up OK for me
Geoff Jefferson
Ranch Hand
Joined: Apr 09, 2009
Posts: 102
posted
May 07, 2009 04:53:57
0
Thank, I found an error in the controller.
I agree. Here's the link:
http://aspose.com/file-tools
subject: ? JTable getColumnName
Similar Threads
Refreshing a window
I don't understand why my JTable will not display data
unable to get row index in JTable
? File I/O (and-or) for each loop
Concerning Custom Table Model
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter