2

I've overridden BasicScrollBarUI, but I don't know how to change the buttons after they've been created. How could I do this? Thanks.

Harry Joy
  • 58,650
  • 30
  • 162
  • 207
rtheunissen
  • 7,347
  • 5
  • 34
  • 65
  • Are you overriding `createDecreaseButton` and `createIncreaseButton` methods and create your custom in it then return them? Which things in button do you want to change after creation? UI of button? – Harry Joy Dec 27 '11 at 06:14
  • Yeah I am overriding these methods but they create a new button and return it. An option could be to create class variables that point to the returned buttons, and modify them. I just want to change the colors - creating an inverted color theme. – rtheunissen Dec 27 '11 at 06:29
  • 1
    See [MetalScrollBarUI](http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Core/swing/javax/swing/plaf/metal/MetalScrollBarUI.java.htm) implementation. The buttons are members of the class and can be updated later. – tenorsax Dec 27 '11 at 06:52

2 Answers2

2

If you mean how to register your implementation of ScrollBarUI then this should help you:

UIManager.put("ScrollBarUI", YourScrollbarUI.class.getName());
tenorsax
  • 21,123
  • 9
  • 60
  • 107
  • At the moment all I have is `scrollPane.getVerticalScrollBar().setUI(new CustomScrollBarUI());` But once I've created the UI object, I can't see how I can update or modify it after I've created it. – rtheunissen Dec 27 '11 at 05:18
  • @paranoid-android You can also try: getVerticalScrollBar().getUI() – tenorsax Dec 27 '11 at 05:32
  • I can reference it fine, but not sure how to update / reinstall. – rtheunissen Dec 27 '11 at 05:38
  • After you call UIManger.put(....) try this `SwingUtilities.updateComponentTreeUI(frame); frame.pack();` – Dimitry Dec 27 '11 at 20:10
2

I think you need to do something like this:

UIManager.put("ScrollBarUI", YourScrollbarUI.class.getName());
SwingUtilities.updateComponentTreeUI(frame); 
frame.pack();

Take a look at this link for more information of how to update the Look and Feel. Look and Feel

Dimitry
  • 4,503
  • 6
  • 26
  • 40