• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why my table's columName invisiable?

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put my table on a JDialog.Everything is OK except the colum name.Bellow is my code.
//TableModel
import javax.swing.table.AbstractTableModel;

public class GeneralTableModel extends AbstractTableModel{
private String[] columnName;
private String[] cell;

public GeneralTableModel(String[] columnName, String[] cell) {
this.columnName = columnName;
this.cell = cell;
}
public int getRowCount() {
return cell.length / columnName.length;
}
public int getColumnCount() {
return columnName.length;
}
public Object getValueAt(int row, int column) {
int index = row * columnName.length + column;
return cell[index];
}
public String getColumName(int column) {
return columnName[column];
}

}

//then I use JBuilder to do GUI design
......
tale = new JTable(tableModel);
.......

Where is the problem?
Thanks!
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To what component is your table added? If it's not inside a scrollpane then

"Note that if you wish to use a JTable in a standalone view (outside of a JScrollPane) and want the header displayed, you can get it using getTableHeader() and display it separately. " - from the api

If it's in a scrollpane, then please can you post the code where you are creating the table and adding it to the scrollpane.

Cheers,
Rachel
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.
I haven't place the table in a ScrollPane in deed.
And in my table model,I haven't overried getColumnName(int column).Instead of that I add a new methord getColumName(int column) by mistake.So when I place my table in a scrollPane,the column name dispaly like that,A, B,...
Now everything is Ok.
I am from China,and not good at english.
I hope I have expressed me clearly.
Thank you!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!