Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JScrollPane - background colour

1,270 views
Skip to first unread message

Krzysztof Sterna

unread,
Jan 23, 2001, 4:36:33 AM1/23/01
to
Hi,
I have a problem with changing a JScrollPane background colour. I tried
these:
myScrollPane.setOpaque(true);
myScrollPane.setBackground(Color.white);
and also
myScrollPane.getViewport().setOpaque(true);
myScrollPane.getViewport().setBackground(Color.white);
but the background still remains gray :((, as if there was some outer layer,
but what is it?
How to change the background???

Any help appreciated,
--

--------------------------------------------
Krzysztof Sterna
krzys_...@poczta.onet.pl
--------------------------------------------


Klaus P. Berg

unread,
Jan 23, 2001, 9:16:58 AM1/23/01
to
Hi,
I'm using Swing with JDK1.3 and the lines
aComponent.setBackground(Color.blue);
JScrollPane scroller = new JScrollPane(aComponent);
scroller.getViewport().setBackground(Color.blue);
create a blue background.
So, what is your environment?
On the other hand: May be you have not set
"aComponent.setBackground(Color.blue);" as above?

Klaus

Linda Radecke

unread,
Jan 23, 2001, 9:25:38 AM1/23/01
to

Krzysztof Sterna escribió:

Hi !

> I have a problem with changing a JScrollPane background colour. I tried
> these:

[...]

> How to change the background???

Are you using 1.3 or an older JDK - version ?
I read something about a bug in prior versions than 1.3 concerning
JScrollPane's background I simply call setBackground() on the
JViewport and so the the following codelines changes the color :

myscroll.getViewport().setBackground(new Color(80,90,155));


Linda
--

"So tell me, my good man, why is a raven like
a writing desk ?" A British accent, precise,
aristocratic. George stumbled free of the
congested clothing like a jungle explorer
breaking into a clearing. "What ?"
James Morrow, This Is The Way The World Ends ,


Linda Radecke

unread,
Jan 23, 2001, 9:27:53 AM1/23/01
to

Krzysztof Sterna escribió:

> I have a problem with changing a JScrollPane background colour. I tried
> these:

[...]

> How to change the background???

Are you using 1.3 or an older JDK - version ?


I read something about a bug in prior versions than 1.3 concerning

JScrollPane's background. I simply call setBackground() on the
JViewport and so the following codelines changes the color :

Krzysztof Sterna

unread,
Jan 23, 2001, 10:58:29 AM1/23/01
to
Hi,
I'm using JDK1.2.2 and my program should work with JDK1.2...

To Klaus:
I add a JTable component to the JScrollPane... the background colour of the
JTable is set to white by default...
The size of JScrollPane is constant, but the size of JTable changes... e.g.
it may contain only two rows and then not the whole JScrollPane is covered
with the table. In this case JScrollPane content is half white and half
gray, which doesn't look good :(

To Linda:
setting background for a JViewport doesn't work in my case... I checked it
again...
Do you remember where you've read about the bug with JScrollPane?

KS


Linda Radecke

unread,
Jan 23, 2001, 11:55:46 AM1/23/01
to

Krzysztof Sterna escribió:

Hi!

> To Linda:
> setting background for a JViewport doesn't work in my case... I checked it
> again...
> Do you remember where you've read about the bug with JScrollPane?

I found the article again containing a possible solution for prior versions,
too :

http://forum.java.sun.com/read/16799962/q_XDXfzdGkL8AAZQE#LR


Linda

--

E wieß Blatt Papier, ne Bleisteff, Jedanke bei dir,
setz ich ahm Finster un hühr, wat sich avvspillt vüür
der Düür, bess ich avvrötsch en die Zigg, en der et
dich für mich nit joov un mir ming Levve vürm Daach
X op einmohl vüürkütt wie en Stroof.
Do kanns zaubere, BAP


Krzysztof Sterna

unread,
Jan 23, 2001, 2:08:36 PM1/23/01
to
"Linda Radecke" <li...@radecke.ch> wrote in message
news:3A6DB792...@radecke.ch...

>
> I found the article again containing a possible solution for prior
versions,
> too :
>
> http://forum.java.sun.com/read/16799962/q_XDXfzdGkL8AAZQE#LR
>

Thanks a lot!!!

The solution given by JoeScheer works very well in JDK1.2.2:

Work-around:
By putting the scroll pane within a panel which is the same size as the
scrollpane AND setting the background color of the panel, the viewport ends
up
picking up the background of the panel.
Example code:
/*
* Workaround for bug 4119459
*/
// Set background color of panel which contains the JTable
m_hTableBackgroundPanel.setBackground(SystemColor.window);
m_hTableBackgroundPanel.setLayout( new BorderLayout() );
// Create a scroll pane for the JTable
m_hStatusTableScrollPane =
JTable.createScrollPaneForTable(m_hStatusTable);
// Add the scroll pane to the panel - The viewport w/in the scroll pane
will pick up the
// background color of the panel.
m_hTableBackgroundPanel.add(m_hStatusTableScrollPane,
BorderLayout.CENTER);


0 new messages