You could try
class MyScrollBarUI extends BasicScrollBarUI {
// this draws scroller
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
g.setColor(Color.BLUE);
g.fillRect((int)trackBounds.getX(),(int)trackBounds.getY(),
(int)trackBounds.getWidth(),(int)trackBounds.getHeight());
}
// this draws scroller background
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
g.setColor(Color.RED);
g.fillRect((int)trackBounds.getX(),(int)trackBounds.getY(),
(int)trackBounds.getWidth(),(int)trackBounds.getHeight());
}
// and methods creating scrollbar buttons
protected JButton createDecreaseButton(int orientation) {
JButton button = super.createDecreaseButton(orientation);
button.setBackground(Color.BLACK);
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
return button;
}
protected JButton createIncreaseButton(int orientation) {
JButton button = super.createIncreaseButton(orientation);
button.setBackground(Color.BLACK);
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
return button;
}
}
...and when you create JScrollPane, to modify let's say vertical scrollbar, simply call --
scrollPane.getVerticalScrollBar().setUI(new MyScrollBarUI());
Thank U...but i got this error while compiling it
cannot find symbol
symbol: class BasicScrollBarUI
class MyScrollBarUI extends BasicScrollBarUI {
i already import javax.swing..but still cannot find symbol...why?
ok..i its solved....they need
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicScrollBarUI;
then still got problem with
cannot find symbol
symbol : variable trackBounds
location: class MyScrollBarUI
g.fillRect((int)trackBounds.getX(),(int)trackBounds.getY(),
then i declare variable trackBounds
Rectangle trackBounds = null;
then its successful compiled
but when i call this class to setUI i got this error...
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at MyScrollBarUI.paintThumb(MyScrollBarUI.java:15)
at javax.swing.plaf.basic.BasicScrollBarUI.paint(BasicScrollBarUI.java:3
66)
please give me some clue....is it because rectangle was null?