aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes specify color for jtable column headings (each column heading color is different) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "specify color for jtable column headings (each column heading color is different)" Watch "specify color for jtable column headings (each column heading color is different)" New topic
Author

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

Jordan Thompson
Greenhorn

Joined: Nov 09, 2009
Posts: 20
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


No matter where you go - there you are
-- Buckaroo Banzai
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Nov 09, 2009
Posts: 20
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

Joined: Nov 09, 2009
Posts: 20
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

Joined: Nov 09, 2009
Posts: 20
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

Joined: Nov 09, 2009
Posts: 20
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();
 
 
subject: specify color for jtable column headings (each column heading color is different)