Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable column question  RSS feed

 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello -
I am trying to determine the size of my columns in my JTable dynamically. I am trying to follow some code provided at http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot3/TableRen derDemo.java regarding table.getTableHeader().getDefaultRenderer(). However, when I try to compile, it is failing, saying
Method getDefaultRenderer() not found in class javax.swing.table.JTableHeader.
TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer();
Here is the code I am using:
JTableHeader tableHeader = table.getTableHeader();
TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer();
Since this is from sun's example, I do not understand my problem. Can anyone help please??
Thanks so much!
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi verduka,
it's the matter of jdk1.3 vs. earlier jdk.
seems that you missed the commented lines on the top of the
the mentioned page which states
----------------------------------
//1.3 changes: column.getHeaderRenderer() ->
// table.getTableHeader().getDefaultRenderer()
---------------------------------------
so in case u r not using jdk1.3 then the line you have mentioned will not be compiled.
i.e. if u are not using jdk1.3 then u'll have to go for
column.getHeaderRenderer() function.
regards
deekasha
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought of this, however I was confused. I am compiling with 1.2.2, but using the 1.3 plug in to enhance to loading speed of the applet. I saw the note in http://java.sun.com/docs/tutorial/uiswing/components/table.html that says
"Because the 1.3 getHeaderRenderer method returns null by default, you generally use the 1.3 getDefaultRenderer method instead."
When I ran the applet through the 1.3 plug in, getHeaderRenderer was returning null. I thought this must be the reason, so I changed it to use table.getTableHeader().getDefaultRenderer() and then it wouldn't compile. Can you tell me why column.getHeaderRenderer() is returning null?? Why doesn't the sample code in the http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/TableRen derDemo.java initColumnSizes() method work for me?
[This message has been edited by verduka fox (edited January 25, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!