• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Dynamic JTable Headers?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick response. This looks simple enough. I will analyze this for a better understanding.
 
Hang a left on main. Then read this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic