I have JTextPane
inside JScrollPane
. When I highlight some word in text pane I want to have their position highlighted on JScrollBar
(Similar to highlighting errors in source code in Eclipse).
Is this possible with Swing?
The "immediate" problem you have is the fact that the scroll pane does not support the concept of "row footers", which would provide you an area on the right hand side of the scroll pane you could render you highlight points
What you need is an implementation that does. You could take a look at JideScrollPane
which provides not only support for row footers, but column footers as well.
From there it's a simple case of using the same concept as decorating a normal scroll pane (row and column header).
Check out Providing Custom Decorations for some hints.
The other choice (I can think of) would be to place a normal JScrollPane
onto a JPanel
using a BorderLayout
so that the scroll pane occupied the center position. This would then allow you to place a custom component to the EAST
position that would act as you "marker" pane.
This is slightly simpler, as it doesn't require a lot of additional changes to be made. You would then need to calculate the position of the text in the view port as a percentage of the it's height, which would allow you to translate it back to the "marker" pane
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.