basicscrollbarui和laf问题

jyztefdp  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(196)

我正在创建一个程序,它有一个nimbuslaf,在那里我使用一个jscrollpane和一个basicscrollbarui。

sp = new JScrollPane(lista);

        sp.getVerticalScrollBar().setUI(new CustomScrollBarUI());

问题是,我需要一些自定义按钮的nimbuslaf,和滚动条的basicscrollbarui,我不能用nimbus,如果我使用我的滚动条都走出边界。就这样
我用于scrollbarui的类是:

protected void paintTrack(Graphics g, JComponent c, Rectangle r) {

        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Color color = ColorPri;
        JScrollBar sb = (JScrollBar) c;
        scrollBarWidth = 9;

        if (!sb.isEnabled()) {
            return;
        } else if (isDragging) {
            color = ColorSec;
        }

        g2.setColor(color);
        g2.fillRect(r.x, r.y, r.width, r.height); 
        g2.setColor(color);
        g2.fillRect(r.x, r.y, r.width, r.height);

    }

    @Override
    protected void paintThumb(Graphics g, JComponent c, Rectangle r) {
      Graphics2D g2 = (Graphics2D) g.create();
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      Color color = null; 
      JScrollBar sb = (JScrollBar) c;

      if (!sb.isEnabled()) {
        return; 
      } else if (isDragging) {
        color = ColorPri; 
      } else if (isThumbRollover()) {
        color = ColorSec; 
      } else {
        color = ColorSec; 
      }

      g2.setPaint(color);
      g2.fillRoundRect(1, r.y, 7, r.height, 5, 5); 
      g2.dispose();
    }

    @Override
    protected void setThumbBounds(int x, int y, int width, int height) {
      super.setThumbBounds(x, y, width, height); 
      scrollbar.repaint();
    }

}

颜色是从主类收到的
有没有什么方法可以修复它而不必删除laf或basicui?提前谢谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题