3

How does one re-set the color of a ScrollBar with a custom BasicScrollBarUI ?

I know I can use this to set the color the first time:

protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)

However, that's called by the constructor, I can't call it again manually.

I need the color of the scrollbar to change when and action triggers.

How do I go about this?

Lory A
  • 520
  • 1
  • 5
  • 17

1 Answers1

0

I'm not sure what you need but please let me know if this helps

ScrollView scr = (ScrollView)findViewById(R.id.scrollView1);
try
{
Field mScrollCacheField = View.class.getDeclaredField("mScrollCache");
mScrollCacheField.setAccessible(true);
Object mScrollCache = mScrollCacheField.get(scr); // scr is your Scroll View

Field scrollBarField = mScrollCache.getClass().getDeclaredField("scrollBar");
scrollBarField.setAccessible(true);
Object scrollBar = scrollBarField.get(mScrollCache);

Method method = scrollBar.getClass().getDeclaredMethod("setVerticalThumbDrawable", Drawable.class);
method.setAccessible(true);

// Set your drawable here.
method.invoke(scrollBar, getResources().getDrawable(R.drawable.scrollbar_blue));
} catch(Exception e) {
e.printStackTrace();
}

listview.mScrollCache.scrollBar.setVerticalThumbDrawable(getResources().getDrawable(R.drawable.scrollbar_style));
zombie
  • 5,069
  • 3
  • 25
  • 54