TableViewer 中字段之间的 Tab 键
我想做的是能够在表中的元素之间进行切换。
我目前正在创建这样的表。
this.tableViewer =
new TableViewer(parent , SWT.FULL_SELECTION);
tableViewer.setUseHashlookup(true);
table = tableViewer.getTable();
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.grabExcessVerticalSpace = true;
table.setLayoutData(gridData);
table.setLinesVisible(true);
table.setHeaderVisible(true);
...
/** Create the Cell Editor Array - will hold all columns **/
editors = new CellEditor[table.getColumnCount()];
/** Cell Editor Row 1 **/
/** Set the column properties **/
tableViewer.setColumnProperties(columnNames);
/** Assign the cell editors to the viewer **/
tableViewer.setCellEditors(editors);
/** Set the cell modifier for the viewer **/
tableViewer.setCellModifier(new MyCellModifier(this));
//Create the Table Viewer
/** Table Viewer Content and Label Provider **/
tableViewer.setContentProvider(new MyContentProvider(this));
tableViewer.setLabelProvider(new MyLabelProvider());
但我不知道如何设置表格。其他一切都可以编辑列、显示数据等。只是停留在最后一部分。
如果我错过了明显的文档或 javadocs - 我很抱歉,甚至指出这些都会很棒。
What I'd like to do is be able to tab between elements in table.
I currently am creating my table like this.
this.tableViewer =
new TableViewer(parent , SWT.FULL_SELECTION);
tableViewer.setUseHashlookup(true);
table = tableViewer.getTable();
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.grabExcessVerticalSpace = true;
table.setLayoutData(gridData);
table.setLinesVisible(true);
table.setHeaderVisible(true);
...
/** Create the Cell Editor Array - will hold all columns **/
editors = new CellEditor[table.getColumnCount()];
/** Cell Editor Row 1 **/
/** Set the column properties **/
tableViewer.setColumnProperties(columnNames);
/** Assign the cell editors to the viewer **/
tableViewer.setCellEditors(editors);
/** Set the cell modifier for the viewer **/
tableViewer.setCellModifier(new MyCellModifier(this));
//Create the Table Viewer
/** Table Viewer Content and Label Provider **/
tableViewer.setContentProvider(new MyContentProvider(this));
tableViewer.setLabelProvider(new MyLabelProvider());
But I'm not sure how to set up the tabulation. Everything else works as far as editing columns, showing data, etc. Just stuck on this last part.
If I've missed obvious documentation or javadocs - my apologies and even pointing to those would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尽管发布的解决方案 thehiatus 级别非常低并且可能会起作用(我还没有测试它),但 JFace 为您提供了解决此特定问题的框架。请参阅 org.eclipse.jface.viewers.TableViewerFocusCellManager 和 org.eclipse.jface.viewers.CellNavigationStrategy 类来解决此问题。
Although the solution thehiatus posted is very low level and will probably work (I haven't tested it), JFace gives you a framework for this specific problem. See the
org.eclipse.jface.viewers.TableViewerFocusCellManager
along withorg.eclipse.jface.viewers.CellNavigationStrategy
classes to solve this problem.我认为默认情况下选项卡不会在 swt 表中从一个单元格跳转到另一个单元格。相反,它会遍历到下一个控件。因此,您还需要告诉它在按下 Tab 时不要遍历。
此外,正如 derBiggi 建议的那样,需要将侦听器添加到 Table 对象,而不是 TableViewer。
I think by default tab does not jump from cell to cell in an swt table. Instead it traverses to the next control. So you'll also need to tell it not to traverse when tab is pressed
Also, as derBiggi suggested, the listeners need to be added to the Table object, not the TableViewer.
我无法使用
TraverseListener
获得所需的行为(它不会在表内遍历),并且无法使其与FocusCellManager
和一起使用CellNavigationStrategy
。我终于找到了这个解决方案,它使我能够在一行中从一列切换到另一列并自动激活编辑器。I couldn't get the desired behavior with a
TraverseListener
(it would not traverse within the table), and I had trouble getting it to work with aFocusCellManager
andCellNavigationStrategy
. I finally found this solution that enables me to tab from column to column within a row and automatically activate the editor.您需要添加一个 KeyListener 并将选择或焦点设置到下一个单元格:
You need to add a KeyListener and set the selection or focus to the next cell:
我还必须在表中的元素之间实现制表符。我们使用 Nebula 的 Grid 作为表格。
首先,我必须抑制焦点的切换,以防止其移出表格。
然后我添加了一个关键侦听器,它将焦点/选择移动到下一个单元格:
我还制作了自己的算法,将选择的单元格向右移动一个单元格,当位于行末尾时,将其移动到下一行的开头。当到达表格末尾时,选择将移回表格中的第一个单元格。
这为我解决了问题。
I also had to implement tabbing between elements in a table. We use Grid from Nebula as the table.
Firstly, I had to suppress tabbing the focus preventing it from moving out of the table.
and then I added a Key Listener which moves the focus/selection to the next cell:
I also made my own algorithm to move the selection one cell to the right and when at the end of the row, move it to the beginning of the next row. When end of table is reached, the selection moves back to the first cell in the table.
This solved the problem for me.