So I use Java Swing to build the UI for my app and use custom images to replace the ugly Java ones, the custom images have a style and are very easy to integrate into Java Swing.
Right now my problem is I need to use a JScrollBar with a JScrollPane in an app and I really don’t want to use either the default Java Scroll Bar or even the native OS Scroll Bar.
I just want to be able to have a custom image be the Background of the scroll bar
and an image to be the Thumb of the scroll bar.
How to make a custom JScrollBar using an image?
I wrote an example that shows how to set a custom image for the thumb and background (called track) of a scrollbar. You need the two files
thumb.pngandtrack.pngfor the custom images in the same place where your class file is. I also do some scaling of the images to fit the scrollbar. Just experiment a little bit with this code. I changed the width of the scrollbar (setPreferredSize) to better see the images too.The essential points are that you have to create your own class
MyUithat extendsBasicScrollBarUIand overridespaintThumbandpaintTrack, and personalize your scrollbar withsetUI(new MyUI):For more information consult the sourcefile
MetalScrollBarUI.java.