• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic JTable Headers?  RSS feed

 
Gary Frick
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to build a dynamic JTable to display the results of a SQL/JDBC Query. After I do the query I get the column names returned. But how do I create the table header dynamically using the resulting column names?
Thanks,
Gary
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch! We don't have too many rules here but you did manage to violate two of them! But don't worry, we are pretty easy on you greenhorns.
Two rules...
1) please do not cross-post. Pick the most appropriate forum for your topic.
2) your name violates the JavaRanch naming standard. Please read this: http://www.javaranch.com/name.jsp and change your display name.
Thanks!
And enjoy your stay at the ranch!
 
Gary Frick
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas & community,
I apologize for inadvertently breaking any rules. In my haste for an answer I have to admit that I did not read all of the fine print. I promise to abide by the rules and I have since changed my name profile to reflect guidelines.
Gary
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not too tough and there are several ways to do it. Here's one:
TableColumnModel tcm = jTable.getColumnModel();
The TableColumnModel represents the form for every column in your table.
TableColumn tc = tcm.getColumn(0);
TableColumn represents the form for a particular column.
tc.setHeaderValue("My New Value");
[ September 13, 2002: Message edited by: Thomas Paul ]
 
Gary Frick
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick response. This looks simple enough. I will analyze this for a better understanding.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!