如何在 Eclipse RCP Table 控件中合并表格单元格?
我的问题是:我认为有一个 Eclipse RCP 表。表格有网格线可见,一切都很好。但我希望表第一行的所有单元格在运行时 GUI 中合并为一行。我怎样才能实现这个功能?拜托,我不希望在第一行添加文本之类的东西阻碍它。如果有任何 API 级别的功能或任何线索来做到这一点,欢迎。
My question is: I've an Eclipse RCP table in my view. The table has gridlines Visible and everything is fine. But I want all the cells of first row of the table to be merged as a single row in run-time GUI. How can I achieve this functionality ? Please, I don't expect something like adding a text over the first row obstructing it. If any API level functionality or any clues to do this are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
swt 表是一个原生小部件,不允许有任何跨度,无论是列还是行。即使OwnerDraw(自定义单元格渲染)也不支持这一点。我认为可以让您实现这种黑客攻击的唯一方法是 swt 表编辑器,它允许您将控件放置在单元格上方:
http://www.eclipse.org/swt/snippets/#tableeditor
表编辑器跟踪单个单元格的位置以及它们上方的位置控件。当单元格不处于编辑模式时,它会隐藏控件;当单元格处于编辑模式时,它会显示它们。您必须停用此默认行为并确保始终显示控件 - 这应该相当容易。
更具挑战性的部分是您必须找出如何将控件放置在 2 个或更多(而不是单个)单元格上方。
我所知道的唯一支持 span 的 swt 控件是星云网格。网格是一个自定义控件(没有本机小部件),因此提供了更多的可能性。
http://eclipse.org/nebula/widgets/grid/grid.php
http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.nebula/org.eclipse.swt.nebula.snippets/src/org/eclipse/swt/nebula/snippets/grid/GridSnippet2。 java?root=Technology_Project&view=co
The swt table is a native widget and does not allow you any span, neither in columns nor in rows. Even OwnerDraw (custom cell rendering) does not support this. The only way I see that could allow you to achieve this kind of hack is the swt table editor which allows you to place controls above cells:
http://www.eclipse.org/swt/snippets/#tableeditor
The table editor tracks the position of single cells and positions controls above them. It hides controls when a cell is not in edit mode, show's them when the cell is in edit mode. You'd have to deactivate this default behavior and make sure the controls are always shown - this should be fairly easy.
The more challenging part would be that you'd have to find out how to place the controls above 2 or more (and not a single) cells.
The only swt control I know to support span is the nebula grid. Grid is a custom control (no native widget) and therefore offers far more possibilites.
http://eclipse.org/nebula/widgets/grid/grid.php
http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.nebula/org.eclipse.swt.nebula.snippets/src/org/eclipse/swt/nebula/snippets/grid/GridSnippet2.java?root=Technology_Project&view=co
您可以使用GC api来完成表中的需求。你可以跨越两列。
http://www.java2s.com/Tutorial/Java/0280__SWT/Maketextspanmultiplecolumns.htm
u can use GC api to do the needs in table. u can span between two columns.
http://www.java2s.com/Tutorial/Java/0280__SWT/Maketextspanmultiplecolumns.htm