Search code examples
javaswingcomparejscrollpanejscrollbar

How can I put a Bar next to the ScrollBar


I am Working with Swing in java and I'm making a little tool to compare 2 Files.

The Comparing works, the differences are marked in Red.

So I tough that I could make a kind of Bar next to the ScrollBar to show where I have to Scroll to find de differences in my text. Something like in Eclipse to show where are Errors, Warnings and TODOs

Another possibility coulb be to put the marks into the ScrollBar.

Is that Possible and if Yes, how can I code this? Thank you for your help


Solution

  • Place your scroll pane in a JPanel with BorderLayout. Add one more JPanel's extension to show all the marks and place it to the east (or west). Place the marks on the panel and add a MouseListener to process clicks and scroll to desired positions.

    Or you can use custom row/column header. Like this http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html