Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make the JScrollPane same color as JTable?

 
Frank Li
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use setPreferredScrollableViewportSize() on JTable to avoid taking extra space. set the dimensions to Min. dimension of JTable.
 
Tim Troy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yijay and Tim:
Thanks for your help. It works !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic