aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Header in JTable  is not showing up.PLEASE...... IT IS URGENT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Header in JTable  is not showing up.PLEASE...... IT IS URGENT" Watch "Header in JTable  is not showing up.PLEASE...... IT IS URGENT" New topic
Author

Header in JTable is not showing up.PLEASE...... IT IS URGENT

Sandeep Ghosh
Ranch Hand

Joined: Jan 23, 2002
Posts: 145
I have create a method which returns JTable. I have inheritied AbstractTableModel and implemented some methods.
then added the JTable into Panel.JTable is showing up but with out header.I have to submit this project tommorow.
Please solve my problem.
Thanks in adv.
Sonu
class TableMap extends AbstractTableModel {
JTable list;
public TableMap(JTable l) {
list = l;
}

public void newTable(JTable l) {
list = l;
}

public String getColumnName(int col) {
return list.getColumnName(col);
}
public int getColumnCount() {
return list.getColumnCount();
}
public Class getColumnClass(int c) {
return list.getValueAt(0, c).getClass();
}
public Object getValueAt(int aRow, int aColumn) {
return list.getValueAt(aRow,aColumn);
}
public int getRowCount() {
return (list.getRowCount());
}
}
//SomeWhere in Panel
JTable result= ConnectionManager.runselectQuery(statement);
if(result!=null)
{
if (tableMap == null)
{
tableMap = new TableMap(result);
jTable = new JTable(tableMap);
add(jTable);
}
else
{
tableMap.newTable(result);
jTable.setModel(tableMap);
add(jTable);
}
repaint();
validate();
Houssam Haitof
Greenhorn

Joined: Oct 04, 2001
Posts: 11
Hi, to have the column names shown, you should add your table to a scrollpane.
example of code lines to add:
JScrollPane jScrollPane = new JScrollPane();
.
.
.
jScrollPane.getViewport().add(MyTable, null);
Sandeep Ghosh
Ranch Hand

Joined: Jan 23, 2002
Posts: 145
Hi Houssam Haitof
Thanks a lot it was big help from .There is still one little problem .First time header is coming up but when I run another query then rows are changing but headers are not changing.
Please help me.
Thanks in adv
Sandeep
if (tableMap == null)
{
tableMap = new TableMap(result);
jTable = new JTable(tableMap);
jScrollPane.getViewport().add(jTable, null);
add(jScrollPane);
}
else
{
remove(jScrollPane);
tableMap.newTable(result);
jTable.setModel(tableMap);
/* jScrollPane.getViewport().add(jTable, null);*/ //if I remove comment then no table appears.
add(jScrollPane);
}
repaint();
validate();
Houssam Haitof
Greenhorn

Joined: Oct 04, 2001
Posts: 11
Hi, use this table model class instead of yours (of course you can add to it anything that you need):

when you have a new result create a new model:
MyTableModel model = new MyTableModel(MyDataArray, MyColumnNames);
then set your table model:
myTable.setModel(model);
and the column names should change along with the data.
N.B.: you should add your table to a scrollpane only once.
[ June 13, 2002: Message edited by: Michael Ernest ]
Sandeep Ghosh
Ranch Hand

Joined: Jan 23, 2002
Posts: 145
Hi Houssam Haitof,
Thanks a lot. You are too good. I was looking for just that type of help. Could I have your email address or will you prefer to receive private message from this forum.
Thanks again.
Sandeep
Houssam Haitof
Greenhorn

Joined: Oct 04, 2001
Posts: 11
You're welcome =)
Just msg me from this forum as it will redirect it to the email adress that I'll most use.
P.S.: I'm still a newbie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Header in JTable is not showing up.PLEASE...... IT IS URGENT