在 Java 文本编辑器中创建类似 Eclipse 的线标记栏
我的 Java GUI 应用程序包含一个可滚动文本窗口。除了标准滚动条之外,我还需要一个带有彩色线条标记的垂直条,就像在 Eclipse 中一样。希望你知道我在说什么。该栏不可滚动,标记位置根据整个文本的高度按比例排列。当用户单击任何标记时,文本框会滚动到相应的行。
我无法在 SWT 小部件套件中找到此类控件。显然 SWT 在某处包含它。对我来说,理想的选择是 Swing 组件,因为应用程序是基于 Swing 的。
非常感谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为 Swing 中没有捆绑组件,也不知道有任何库提供这样的组件,但您应该能够自己完成。
在滚动窗格旁边提供一个面板,每当滚动窗格/文本窗格重新渲染时,也会重新渲染该面板。然后根据线条放置标记(第一步可以是 JLabels,稍后绘制自己的标记并添加鼠标处理) - 在这种情况下布局管理器应该为空。
可以使用 line/numlines * height(panel) 来计算位置,例如,对于 100 的第 20 行和 200 的面板高度,标记的位置将位于高度 20/100 * 200像素 = 40 像素。
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.您想要的标尺不是来自 SWT。它来自 jface-text 插件。您正在寻找的课程是 org.eclipse.jface.text.source.CompositeRuler
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
如果您仍然询问,这里有一个(非免费)标记栏组件:
http://www.sideofsoftware.com/marker_bar.htm
In case you are still asking, here is a (not-free) marker bar component:
http://www.sideofsoftware.com/marker_bar.htm