it-notepad.com

How to dynamically change arrow buttons in BasicScrollBarUI

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(){
   decrButton.setIcon(decreaseIconEneterd);
   incrButton.setIcon(increaseIconDefault);
}
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();
...
scrollUi.setButtonsPressed();
//and we can set default butoons - scrollUi.setButtonsDefault();

 

Exit mobile version