• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Why my table's columName invisiable?

 
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!
 
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!
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic