File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Drawing my own ScrollBar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drawing my own ScrollBar" Watch "Drawing my own ScrollBar" New topic

Drawing my own ScrollBar

Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
I have an application where we parse data from a file and then display it in a JTable within a JScrollPane. I want to "draw" an extra two buttons on the ScrollBar, one on the very top above the existing top button and one on the very bottom below the existing bottom button. These buttons would basically be used as "page up" and "page down" buttons, the bottom one parsing the next xx entries in the file and adding them to the bottom of the table when the user is already viewing the last entry. I'm not sure how to go about this.

I already have routines in place to handle the page up and page down behavior but what I don't know how to do is draw these buttons. I've used paint() before for things like drawing images and shapes but I have no idea how to go about drawing these simple little buttons, there's the L&F to deal with and everything. How the heck do I go about this? Can I subclass JScrollBar and just draw an extra button on top and the bottom? What the heck do I do? I've been searching for an article that would help me with doing something like this but I've failed to find one. Any help is appreciated.
David Mace
Ranch Hand

Joined: May 26, 2004
Posts: 35
I think the solution to this would be to subclass the JScrollPane itself and then override the painting functions to implement the new buttons you are talking about...and of course to add their functionality. I would suppose this isn't a trivial task, but it's doable nonetheless.

Examine the source for JScrollPane and you'll get a feel for what needs to be done.


Dad always thought laughter was the best medicine, which I guess is why several of us died of tuberculosis. -Jack Handy
I agree. Here's the link:
subject: Drawing my own ScrollBar
jQuery in Action, 3rd edition