Java 如何将选定行的值从tableviewer传递到SWT中的文本框
我有一个有10行的表格,我想做的是:当我点击“修改”按钮时,我想将所选表格行值传递给相应的文本框 我试过一些代码,但不能完全满足我的需要Java 如何将选定行的值从tableviewer传递到SWT中的文本框,java,swt,Java,Swt,我有一个有10行的表格,我想做的是:当我点击“修改”按钮时,我想将所选表格行值传递给相应的文本框 我试过一些代码,但不能完全满足我的需要 MainTable.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { String string = ""; TableItem[] selection = MainTable.getSelection();
MainTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
String string = "";
TableItem[] selection = MainTable.getSelection();
for (int i = 0; i < selection.length; i++)
string += selection[i] + " ";
final String Appname=string.substring(11, string.length()-2);
System.out.println(Appname);
}
});
MainTable.addListener(SWT.Selection,new Listener()){
公共无效handleEvent(事件e){
字符串=”;
TableItem[]selection=MainTable.getSelection();
for(int i=0;i
上面的代码正在控制台中打印所选的行值,我想将这些值设置为文本框
我如何才能做到这一点?以下是一些示例代码:
private static int columns = 3;
private static List<Text> texts = new ArrayList<>();
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(columns, false));
Table table = new Table(shell, SWT.FULL_SELECTION);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, columns, 1));
table.setHeaderVisible(true);
/* Create columns */
for (int col = 0; col < columns; col++)
{
new TableColumn(table, SWT.NONE).setText("Col " + col);
}
/* Create cells */
for (int row = 0; row < 10; row++)
{
TableItem item = new TableItem(table, SWT.NONE);
for (int col = 0; col < table.getColumnCount(); col++)
{
item.setText(col, "Cell " + row + " " + col);
}
}
/* Pack columns */
for (int col = 0; col < table.getColumnCount(); col++)
{
table.getColumn(col).pack();
}
/* Create the Text fields */
for (int col = 0; col < columns; col++)
{
Text text = new Text(shell, SWT.BORDER);
texts.add(text);
}
/* Listen for selection */
table.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event e)
{
Table table = (Table) e.widget;
TableItem item = table.getItem(table.getSelectionIndex());
/* Fill the texts */
for (int col = 0; col < table.getColumnCount(); col++)
{
texts.get(col).setText(item.getText(col));
}
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static int columns=3;
私有静态列表文本=新的ArrayList();
公共静态void main(字符串[]args)
{
显示=新显示();
最终外壳=新外壳(显示);
shell.setText(“StackOverflow”);
setLayout(新的GridLayout(columns,false));
表格=新表格(外壳、SWT、全套选择);
setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,true,columns,1));
表.setheadervible(true);
/*创建列*/
for(int col=0;col
看起来像这样:
“我想将这些值设置到文本框中”这些
Text
小部件是否已经存在,或者您想动态创建它们?文本框已经存在…顺便说一下:请继续。否则会让人困惑。