• 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 color problem

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using JTable and I have added it to JScrollPane. Now I want to
change color of JTable. I have tried to set background of both table and
scrollpane but it didn't work. If table has two row it will have default
color but remaining table should have white background.


Any Help...
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
to change the backgroud of the whole table implement this
--> table.setBackground(Color.red);

If you would like that the filled rows sholud have different colors from the one that are empty then you have to write another class implementing TableCellRenderer and then call

TableCellRenderer renderer = new MytableRenderer();
table.setDefaultRenderer(Object.class, renderer);

and in this overload function "getTableCellRendererComponent(..)" where in you can specify color for each row.
 
Why fit in when you were born to stand out? - Seuss. 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