• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

specify color for jtable column headings (each column heading color is different)

 
Jordan Thompson
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to set the color of each column heading separately. This _seems_ like it should work, but it actually just blanks out the column headings (including the first three columns.)
When this runs, row is always -1 (as one would expect) and the column increments appropriately.

Here is my humble attempt that did not work (I want to leave the first three column heading colors alone):



Any suggestions would be greatly appreciated!
thanks in advance
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try adding these lines in getTableCellRendererComponent

setBorder(UIManager.getBorder("TableHeader.cellBorder"));
setHorizontalAlignment(JLabel.CENTER);
setText(String.valueOf(value));
setOpaque(true);
return this;

and if you want only the first 3 to remain the same, the if would be > 2 (0,1,2)
 
Jordan Thompson
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:try adding these lines in getTableCellRendererComponent

setBorder(UIManager.getBorder("TableHeader.cellBorder"));
setHorizontalAlignment(JLabel.CENTER);
setText(String.valueOf(value));
setOpaque(true);
return this;

and if you want only the first 3 to remain the same, the if would be > 2 (0,1,2)


Genius! Thanks very much for your help.
 
Jordan Thompson
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas on how to force the update so the colors get set without the user clicking on the heading?

thanks again!
 
Jordan Thompson
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jordan Thompson wrote:Any ideas on how to force the update so the colors get set without the user clicking on the heading?

thanks again!


Nevermind - this works:

 
Jordan Thompson
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jordan Thompson wrote:
Jordan Thompson wrote:Any ideas on how to force the update so the colors get set without the user clicking on the heading?

thanks again!


Nevermind - this works:



Actually, this works better:

myTableView.getTable().getTableHeader().repaint();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic