• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How to add/name row headers?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a couple of sql statements running through various buttons that all display into a single Jtable, upon click of a second button, the results clear. I currently don't have any row headers for the table, but want to add some. I'm not entirely sure how to do that though.
I tried


but that only made my table have empty columns and rows.

This is a small sample of my program



If anyone could point me in the direction of how to add row hearders I would appreciate it
 
Marshal
Posts: 25135
64
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all I've moved this post to the Swing forum.

Then about your JTable question, I think it would be best if you had a look at Oracle's tutorial How to Use Tables. It comes with sample code which you can modify for your own use.
 
Rancher
Posts: 3130
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post a proper SSCCE when asking a question.

We don't know the context of how the code you posted is used so we can only guess.

I currently don't have any row headers for the table,


The row header only appear when you add the table to a JScrollPane.

When you create the JTable the basic logic should be something like:


Then you can later update the table by using the setModel(...) method.

Also, for your SQL you should be using a PreparedStatement. It will make the SQL easier to code and maintain and is less error prone.

I would also recommend you stop using setBounds(...) and learn how to use layout managers. Swing was designed to be used with layout managers.

The tutorial link from above will have examples that use layout managers.
 
We noticed he had no friends. So we gave him this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!