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

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

I create a JTable using DefaultTablemodel with initially zero row. table is added in a JscollPane table's row increase dynamically according to some events. I provide the size to table using setBounds(int,int,int,int) of JScrollPane. also provide the backgound color using SetBackground(Color) of JTable . Then I want to provide color the entire setBounds(int,int,int,int) area. how to do it? This is normaly fine in the case JButton,JCheckBox etc. But there is a problem in the case of JTable.

redards Francis Varkey
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are settings the bounds of the table or the scroll pane?

If the size of the table is smaller than the viewport, which
is extremely likely if the table has zero rows, then you are
seeing the the scrollpane's background.
 
francis varkey
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am setting bounds to Srollpane. but I see the background color as gray color. I am sure this is not the background color of Srollpane or the JPanel.
Becuase I am setting different background color to Srollpane and JPanel.
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can show us some code? Strip out only the frame/panel/layout/color stuff and let us take a look at it. Table too, but shouldn't need to see your TableModel.
 
francis varkey
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
panel.setLayout(null);
panel.setBackground(new Color(240,255,255));

String head[]={"City","Date","HotelName"};
model=new DefaultTableModel(head,0);
table=new JTable(model);
JScrollPane scroll=new JScrollPane(cart_hstable,v,h); // (v,h)Constants

scroll.setBounds(20,30,950,280);

panel.add(scroll);
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try getContentPane().setBackground(Color). I've found that will fill in the areas that just using setBackground(Color) sometimes doesn't.
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said before, it's not the table's background you are seeing,
but the scroll pane's. Or to be more precise, the background of
the scroll pane's viewport. You'll get the effect you want with
scroll.getViewport().setBackground(Color.pink), or probably
use a color you like better than pink.

btw, is there a reason you are setting the layout manager to null
and calling setBounds? This has nothing to do with your background
color problem, of course, but I'd prefer something like this
[ December 12, 2006: Message edited by: Brian Cole ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic