extends jtable

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
 
6

6e

I fixed it! Thanks to your example, I decided to write a new table
class, and slowly add the code from my previous works...

Basically when I overrode (tableChanged), it caused my table to
literally throw up all of its data and blank out on me. EVEN WHEN IT
WAS A BLANK FUNCTION!

Man that pissed me off.

Thanks for the help everyone!
 
A

Andrew Thompson

Basically when I overrode (tableChanged), it caused my table to
literally throw up all of its data and blank out on me. EVEN WHEN IT
WAS A BLANK FUNCTION!

I find that completely unastounding, did you do any
tracing to find what was calling it? What about when
you overode it to simply call 'super()'?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,228
Latest member
MikeMichal

Latest Threads

Top