C
cym tronik
I made a class that extends jtable. But its acting a bit weird.
The first thing I do in the constructor is to call the
super(data,columnnames). This would seemingly make a Jtable object
yes?
However each time that I try to say... this.getColumnCount(), the
result is 0. if I try to get a specific column, of course I get a
arrayindexoutofbounds -1 error.
Im confused and lost as to what the problem is...
Ive posted some simplified code below for your perusal...
Thanks!
-----------"main" code--------------------------------
String[] columnNames = {"Format Label", "Role", "Name", "", "", "", "",
""};
Object[][] data = {
{" ", " ", " ", imgSpecial, imgUp, imgDown, imgToTop, imgToBottom},
{" ", " ", " ", imgSpecial, imgUp, imgDown, imgToTop, imgToBottom}
};
myTable = new MyTable(data, columnNames);
----MyTable constructor...------------------------------------
public MyTable(Object[][] data, String[] columnNames){
super(data,columnNames);
//set font size
this.setFont(new Font("Courier", Font.PLAIN, 13));
//no column moving
this.getTableHeader().setReorderingAllowed(false);
System.out.println("Hltable column count =" + this.getColumnCount());
//equals zero!
this.getColumnModel().getColumn(this.convertColumnIndexToView(iRole));
//breaks the code with an arrayindexoutofbounds error..
I often subclass JTables, exactely in the way you do. I do so because
I need some additional information beeing bundled with the table. I
have no problems with them.
here is my working code, taken from a application that deals with 30 M
CHF per year, so you imagine it was tested thoroughly:
class _Table extends JTable
{
private String[] _aSet;
// CONSTRUCTOR ...................................................................
public _Table(String[][] values, Object[] header, String[] a) {
super(values, header);
_aSet = (String[])a.clone();
} // constructor
// getTexts ----------------------------------------------------------------------
public String[] getTexts() {
return _aSet;
} // getTexts
} // class _Table
the Java version is j2sdk1.4.2_04
Cymtron