Creating Eclipse-like line markers bar in Java text editor
My Java GUI app contains a scrollable text window. Besides a standard scrollbar, I need a vertical bar with colored line markers, like in Eclipse. Hopefully开发者_开发知识库 you know what am I speaking about. This bar is not scrollable, markers positions are arranged proportionally to the height of the whole text. When user clicks on any marker, text box scrolls to the corresponding line.
I were not able to find such control in SWT widget suites. Obviously SWT contains it somewhere. The ideal option for me would be Swing component because application is Swing-based.
Many thanks in advance.
I don't think there is a component bundled with Swing and I don't know of any library supplying such a component, bu you should be able to do it yourself.
Provide a panel next to the scrollpane and whenever the scrollpane/textpane are rerendered rerender that panel, too. Then place markers (could be JLabels in a first step, later draw your own and add mouse handling) according to the lines - the layout manager should be null in this case.
The position could be calculated by using line/numlines * height(panel)
, e.g. for line 20 of 100 and a panel height of 200, the position of the marker would be at height 20/100 * 200 pixels = 40 pixels.
The ruler you want is not from SWT. Its from the jface-text plugin. The class you are looking for is org.eclipse.jface.text.source.CompositeRuler
In case you are still asking, here is a (not-free) marker bar component: http://www.sideofsoftware.com/marker_bar.htm
精彩评论