怎么设置jscrollpane的滚动条外观啊,包括滚动条所在的滚动区域

解决方案 »

  1.   

    自定义一个UI类CustomScrollBarUI,让它继承自
    javax.swing.plaf.basic.BasicScrollBarUI,
    跟据需要重写
    protected void configureScrollBarColors()protected
    JButton createDecreaseButton(int orientation)
    protected JButton createIncreaseButton(int orientation)
    等方法,然后在ScrollPane 中设置新的UI
    yourScrollPane.getVerticalScrollBar().setUI(new CustomScrollBarUI());
    就可以了。
      

  2.   


    import java.awt.Color;import javax.swing.JButton;
    import javax.swing.LookAndFeel;
    import javax.swing.plaf.basic.BasicArrowButton;
    import javax.swing.plaf.basic.BasicScrollBarUI;public class CustomScrollBarUI extends BasicScrollBarUI {
        protected void configureScrollBarColors() {
    LookAndFeel.installColors(scrollbar, "ScrollBar.background",
    "ScrollBar.foreground");
    thumbHighlightColor = Color.red; // 在这里改成你想要的颜色
    thumbLightShadowColor = Color.yellow; // 在这里改成你想要的颜色
    thumbDarkShadowColor = Color.blue; // 在这里改成你想要的颜色
    thumbColor = Color.green; // 在这里改成你想要的颜色
    trackColor = Color.gray; // 在这里改成你想要的颜色
    trackHighlightColor = Color.black; // 在这里改成你想要的颜色
    }
        
        protected JButton createDecreaseButton(int orientation)  {
            return createIncreaseButton(orientation);
        }
        
        protected JButton createIncreaseButton(int orientation) {
    return new BasicArrowButton(orientation, thumbColor,
    thumbLightShadowColor, thumbDarkShadowColor,
    thumbHighlightColor);
        }
    }
    用的时候:yourJScrollPane.getVerticalScrollBar().setUI(new CustomScrollBarUI());就行了
      

  3.   

    可以的,重写protected JButton createDecreaseButton(int orientation),
    protected JButton createIncreaseButton(int orientation)
    返回一个包含图片的JButton,详见JButton类…