Toby
Toby

Reputation: 9803

Custom display of JScrollPane's actual scroll bars (make transparent)

I have a text area with a JScrollPane and am tailoring the display with things like;

    JTextArea text = new JTextArea();
    text.setOpaque(false);
    text.setFont(...);
    text.setForeground(Color.white);
    text.setBackground(Color.black);
    JScrollPane scroll = new JScrollPane(text);
    scroll.setOpaque(false);
    scroll.getViewport().setOpaque(false);

and the scroll and text area are showing as transparent (non-opaque), however, I can't seem to affect the actual scroll bars. They still appear as the default grey color where I'd like to change their color and/or make them transparent to match the rest.

I've tried things like

     scroll.setBackground(Color.black);
     scroll.getVerticalScrollBar().setOpaque(false);

but it doesn't make any difference.

What's the preferred way to do a custom display for the scroll bars?

Upvotes: 1

Views: 932

Answers (1)

mKorbel
mKorbel

Reputation: 109823

and the scroll and text area are showing as transparent (non-opaque), however, I can't seem to affect the actual scroll bars. They still appear as the default grey color where I'd like to change their color and/or make them transparent to match the rest.

there are two ways

  • you would need to override BasicScrollBarUI(),

  • without any commnets milion dollars baby by @aterai,

  • there is VerticalScrollBar only, you need to override and add HorizontalScrollBar, to ScrollPaneLayout() that returns coordinated for Horizontal JScrollBar,

Upvotes: 1

Related Questions