I created my own MyScrollbarUI
class to have a custom scrollbar look in my application. Now I have to do
scrollPane.getHorizontalScrollBar().setUI(new MyScrollbarUI());
scrollPane.getVerticalScrollBar().setUI(new MyScrollbarUI());
on any ScrollPane
I use.
Is it somehow possible to tell Swing
that it should use MyScrollbarUI
on any scrollbar. Maybe via the UIManager
?
We know that Swing is a GUI widget toolkit for Java. Every application has some basic interactive interface for the user. For example, a button, check-box, radio-button, text-field, etc. These together form the components in Swing.
UIManager.put("ScrollBarUI", MyScrollbarUI.class.getName());
should do the trick.
You need to have a public static ComponentUI createUI(JComponent c)
method in your UI class, returning an instance of your UI.
Try putting your custom UI class as ScrollPaneUI
property of UIManager
. By default it is javax.swing.plaf.metal.MetalScrollPaneUI
change it to your custom class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With