How to dynamically change arrow buttons in BasicScrollBarUI

We have daughter class:

public class MacOsScrollUi extends BasicScrollBarUI {

private ImageIcon decreaseIconDefault;
private ImageIcon increaseIconDefault;
private ImageIcon decreaseIconEneterd;
private ImageIcon increaseIconEntered;

    public MacOsScrollUi(){
        decreaseIconDefault = new ImageIcon(...); 
        increaseIconDefault = new ImageIcon(...); 
        decreaseIconEneterd = new ImageIcon(...); 
        increaseIconEntered = new ImageIcon(...); 

    @Override protected JButton createIncreaseButton(int orientation) {
       JButton increaseButton = new JButton(decreaseIconDefault);
       return decreaseButton ; 

    @Override protected JButton createDecreaseButton(int orientation) {
       JButton decreaseButton = new JButton(decreaseButtonDefault);
       return decreaseButton ; 

In classMacOsScrollUi we create two methods for set new arrow Icon for increase and decrease buttons:

public void setButtonsPressed(){
public void setButtonsDefault(){
    decrButton.setIcon(decreaseIconDefault );
    incrButton.setIcon(increaseIconDefault );

And now we can simply change arrow buttons in any position of code:

MacOsScrollUi scrollUi = new MacOsScrollUi();
//and we can set default butoons - scrollUi.setButtonsDefault();

Leave a Reply

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.