Issue with BasicScrollBarUI and LAF

27 Views Asked by At

I'm creating a program which has a Nimbus laf, in there i'm using a JScrollPane with a BasicScrollBarUI.

sp = new JScrollPane(lista);
        
        sp.getVerticalScrollBar().setUI(new CustomScrollBarUI());

The problem is that i need the Nimbus laf for some custom buttons, and the BasicScrollBarUI for the scroll bar which i can't make with Nimbus, if i use both my scrollbar gets out of the border. Just like that

The class i'm using for ScrollBarUI is:

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();
    }
 
    
}

The colors are received from the main class

Is there any way to fix it without having to delete the laf or the basicUI? Thanks in advance

0

There are 0 best solutions below