Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes How to make the JScrollPane same color as JTable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to make the JScrollPane same color as JTable?" Watch "How to make the JScrollPane same color as JTable?" New topic
Author

How to make the JScrollPane same color as JTable?

Frank Li
Greenhorn

Joined: Aug 07, 2003
Posts: 10
Thanks for the people who answered my previous questions.
I am having a problem with color. I have a JTable in side the JScrollPane. The content of this table is updated based on the user's selection. If the
JTable cannot take all space of the JScrollPane, the unused part of the pane is grey and the table is white. How can I make them the same color white?
I tried to set the JScrollPane color as follows
JTable table = new JTable(myTabModel);
JScrollPane tableScroller = new JScrollPane(table);
tableScroller.setForeground(Color.white);
tableScroller.setBackground(Color.white);
Do not work.
Thanks!
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
use setPreferredScrollableViewportSize() on JTable to avoid taking extra space. set the dimensions to Min. dimension of JTable.
Tim Troy
Ranch Hand

Joined: Apr 02, 2003
Posts: 51
From the JScrollPane javadoc:
A common operation to want to do is to set the background color that will be used if the main viewport view is smaller than the viewport, or is not opaque. This can be accomplished by setting the background color of the viewport, via scrollPane.getViewport().setBackground(). The reason for setting the color of the viewport and not the scrollpane is that by default JViewport is opaque which, among other things, means it will completely fill in its background using its background color. Therefore when JScrollPane draws its background the viewport will usually draw over it.
Frank Li
Greenhorn

Joined: Aug 07, 2003
Posts: 10
Hi Yijay and Tim:
Thanks for your help. It works !
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to make the JScrollPane same color as JTable?