how to change JTable Background Color default to white?

I have a JTable that I am displaying in a JScrollpane. The JTable only displays a few rows of information in its grid. The space below the grid to the bottom of the JPanel, that contains the JScrollpane, (Which in turn contains the JTable) is colored solid gray. I'd like to change that color to white. I tried setting the JTable's background color to white, [using the method setBackground(Color,WHITE) ] but that didn't work.

Can anyone tell me which method to use to change that gray to white?

Answers


depend of your code

  • JTable#setFillsViewportHeight(true);

or

  • JScrollPane#getViewport().setBackground(JTable#getBackground());

or you can to fits JScrollPanes JViewport to the JTables view by

  • JTable#setPreferredScrollableViewportSize(JTable#getPreferredSize());

All you have to do is to get the JViewport of the JScrollPane in your JTable and set its background color.

JTable table=new JTable(model);  
JScrollPane scroll=new JScrollPane(table);  
scroll.getViewport().setBackground(Color.WHITE);

Hope that gives a solution, for making your remaining table space as WHITE.


Need Your Help

Is there a way to use an existing function as a part of a class? If yes, how?

c++ function class

I have a function that I want to use in different classes. Is this possible?

Get specific string by XSL

xml xslt

Hi by using this XSL code

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.