• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable - single column header won't change from "A"

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried numerous ways of changing the column header for the single column in a JTable. The following code WORKS in a simple example app I made, but doesn't work in my "real app". Is there something that could be "blocking" changing the column header assignment? I use a "new" DefaultEditor" or "Default renderer" but I don't mess with any headers in them?


Renderer code:
 
Kurt Peters
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pretty interesting, but I noticed from the source code that if columnIdentifiers is not initialized then it outputs super.getColumnName(index).

So, I modified my tableModel to intiate the columnIdentifiers:


That seems to allow me to get rid of the A, but I still can't dynamically change the column headers from the initial value. :-(
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> I've tried numerous ways of changing the column header for the single column in a JTable.

don't know what you're trying to do with all that (didn't read most of it),
but this works OK for me (even when columns are dragged to a new pos)

 
Kurt Peters
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found that the number of columns wasn't being initialized -- (I returned "1") in the "getColumnCount()" of the TableModel, but that isn't the only thing that needed to be done. "setColumnCount()" had to be called to initialize the right variables, allowing storage of the values.
Kurt
 
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic