• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic