• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable and XP column issue

 
Phillip Gibb
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a class that extends JTable and takes a TableModel in the contructor with which it Auto Creates the Columns.

But for some reason in Windows XP (not 2K), the column header is not displayed in fact it appears disabled, huh?

any ideas?

Phill
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Phillip,

Are you using a ScrollPane? I have no problems with headers in my XP system. If you post some code someone might help you.

Ed
 
Phillip Gibb
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have two AbstractTableModel (mainModel and fixedColumnModel).
jtbList : the IntecMatrixTable placed on jspList (this is formed from an empty contructor)
jspList : the scrollpane

IntecMatrixTable :

public IntecMatrixTable(){

super();
setAutoCreateColumnsFromModel(true);
setColumnSelectionAllowed(true);
setRowSelectionAllowed(true);
setCellSelectionEnabled(true);
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}

public IntecMatrixTable(TableModel dm){
super(dm);
setAutoCreateColumnsFromModel(true);
TableColumnModel cm = getColumnModel();
setColumnSelectionAllowed(true);
setRowSelectionAllowed(true);
setCellSelectionEnabled(true);
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}

the follow is called when the a button is pressed:

fixedTable = new IntecMatrixTable(fixedColumnModel);
fixedTable.setEnabled(false);
fixedTable.getColumnModel().getColumn(0).setPreferredWidth(170);
//Set cell renderer for Transaction column. Customised CellRenderer used.
fixedTable.getColumnModel().getColumn(0).setCellRenderer( cellRenderer );
fixedTable.getColumnModel().getColumn(0).setResizable(false);
fixedTable.getTableHeader().setReorderingAllowed(false);

jtbList.setModel(mainModel);
jtbList.setSelectionModel(listSelectModel);
jtbList.addMouseListenerToHeaderInTable();

jspList.getViewport().add(jtbList, null);
Dimension fixedSize = fixedTable.getPreferredSize();
fixedSize.width = 170;
JViewport viewPort = new JViewport();
viewPort.setView(fixedTable);
viewPort.setPreferredSize(fixedSize);
jspList.setCorner(JScrollPane.UPPER_LEFT_CORNER,
fixedTable.getTableHeader());
jspList.setRowHeaderView(viewPort);

jtbList.setCellSelectionEnabled(true);

jtbList.getTableHeader().setPreferredSize(
new Dimension(jtbList.getTableHeader().getWidth(), 19));

jtbList.repaint();


thanks

Phill
 
kumari Jain
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you can try adding these lines

jspList.setLayout(new BorderLayout());
jspList.add(jtbList.getTableHeader(), BorderLayout.NORTH);
jspList.add(jtbList, BorderLayout.CENTER);

Regards,
Kumari
 
Phillip Gibb
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jspList is aScrollPane so I can use only ScrollPaneLayout.
Also I want the coumn header displayed on the column not the table header on the scrollpane because there are more columns with different headers that can be added.

The fixedColumnModel is for the row headers and the mainModel is for the actual column.

The fixedColumnModel overides columnName to return ""; but if I add text there it is shown.

The MainModel is for the actual column and it uses a vector to extract the coumnName to be displayed. The debug there prints out the actual value, so the returned value is correct- but this value is not displayed on WIN XP, but it is dsplayed in WIN2K.

Phill
 
Phillip Gibb
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I worked around this problem by setting the columnheader renderer to a DefaultTableCellRenderer I 'overrode' and then setting the value from the model within the mothod: getTableCellRendererComponent.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!