|
-
Jun 6th, 2004, 09:27 PM
#1
Thread Starter
Banned
-
Jun 7th, 2004, 01:09 AM
#2
Thread Starter
Banned
Hey I have worked out the problem but I have a question...
What's the Result of this statement?
String.class
Does this return the class of String?
-
Jun 7th, 2004, 05:22 AM
#3
New Member
yes String.class will return the class object of the string class.
Life is too short for chess!
http://monkeynick.blogspot.com
-
Jun 7th, 2004, 08:45 PM
#4
Thread Starter
Banned
Originally posted by njadams
yes String.class will return the class object of the string class.
But why won't it work when I use it in JTable maybe I'm doing something wrong...
In JTable I'm using my own cell renderer and my own table model
to set renderers in JTable you'll have to do like either the following statements right.
Code:
table.setDefaultRenderer(table.getModel().getColumnClass(0), new StringRenderer());
--> This code works fine but
Code:
table.setDefaultRenderer(String.class, new StringRenderer());
--> This code doesn't work...
Am I right in my assumption that the table.getModel().getColumnClass(0) and the String.class
should return the same value?...
But why won't the renderer come out when I use the latter statement? Am I doing something wrong?
BTW
in my table model the function getObjectAt always returns a String Object.
-
Jun 8th, 2004, 03:06 AM
#5
New Member
Am I right in my assumption that the table.getModel().getColumnClass(0) and the String.class
should return the same value?...
Yes and no, they should both return a Class Object.
However this may not refer to the same class, the String.class returns the Class Object for the String class. unless you have rewritten the method it will return the Class Object of the Object class.
Code:
package testing;
import javax.swing.*;
public class ClassTest
{
public static void main(String[] args)
{
Class strClass = String.class;
System.out.println("strClass.getName() = " + strClass.getName());
JTable tab = new JTable();
Class tabClass = tab.getModel().getColumnClass(0);
System.out.println("tabClass.getName() = " + tabClass.getName());
}
}
running this will result in:
Code:
String.class = class java.lang.String
tab.getModel().getColumnClass(0) = class java.lang.Object
I'm sorry I can't be more help
Life is too short for chess!
http://monkeynick.blogspot.com
-
Jun 8th, 2004, 03:12 AM
#6
Thread Starter
Banned
Oh yeah... I didn't override that one... I thought that when I've overridden the getValueAt and returned a String Object it will be ok...
Thank you for the enlightenment. . You're a great help... Im such a dork sometimes... Thanks a lot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|