请问如何获取Tabel表中一列的数据啊 我想当鼠标单击Table时候能返回所单击这一行的所有数据,请问怎么实现,用什么数据类型来接受数据?还有谁能说下Table的所有事件有什么啊?高手帮帮忙了谢谢大家!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个跟Java没什么关系,用JavaScript实现即可。 javascript??我说的是Swing组件里的JTable啊怎么获取选中的这一行的数据 不好意思,我不会Swing,下面是SWT代码,差不多。package com.lifesting.table;import org.eclipse.jface.dialogs.MessageDialog;import org.eclipse.swt.SWT;import org.eclipse.swt.events.MouseAdapter;import org.eclipse.swt.events.MouseEvent;import org.eclipse.swt.layout.FillLayout;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableColumn;import org.eclipse.swt.widgets.TableItem;public class DemoTable { private Table table; protected Shell shell; /** * Launch the application * @param args */ public static void main(String[] args) { try { DemoTable window = new DemoTable(); window.open(); } catch (Exception e) { e.printStackTrace(); } } /** * Open the window */ public void open() { final Display display = Display.getDefault(); createContents(); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } /** * Create contents of the window */ protected void createContents() { shell = new Shell(); shell.setLayout(new FillLayout()); shell.setSize(500, 375); shell.setText("Demo"); table = new Table(shell, SWT.FULL_SELECTION | SWT.BORDER); table.addMouseListener(new MouseAdapter() { public void mouseDown(final MouseEvent e) { TableItem[] selected = table.getSelection(); if (selected.length > 0) { TableItem current = selected[0]; String row_data = ""; for (int i = 0; i < table.getColumnCount(); i++) { row_data += current.getText(i)+" "; } MessageDialog.openInformation(shell,"Row Data",row_data); } } }); table.setLinesVisible(true); table.setHeaderVisible(true); final TableColumn nameCol = new TableColumn(table, SWT.NONE); nameCol.setWidth(237); nameCol.setText("Name"); final TableColumn homeCol = new TableColumn(table, SWT.NONE); homeCol.setWidth(147); homeCol.setText("Home"); final TableColumn ageCol = new TableColumn(table, SWT.NONE); ageCol.setWidth(100); ageCol.setText("Age"); final TableItem r1 = new TableItem(table, SWT.BORDER); String[] row = {"David Chan","Hubei","20"}; r1.setText(row); final TableItem r2 = new TableItem(table, SWT.BORDER); row = new String[]{"Joe Wang","Anhui","30"}; r2.setText(row); // }} java中有关对象数组的问题! 一个线程的东西没执行完,怎么用另外的线程调用 <<散分>>终于啃完Head first Java,接下来是该看实例开发还是深一点的书 100分问一个线程同步问题,在线等.谢谢! 50分问一个java布局的问题 用PreparedStament怎么建立条件式查询? Java包访问权限问题 请问各路大侠 一个正则表达式的问题 查错给分!!!!!!!!!!帮忙啦!! [问题]如何像网络蜘蛛哪样爬取网页 Java 利用 POI 输出Excel的页眉页脚是乱码 请教! 如何将用户输入字符串中的英文"转换成\"
怎么获取选中的这一行的数据
package com.lifesting.table;import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class DemoTable { private Table table;
protected Shell shell; /**
* Launch the application
* @param args
*/
public static void main(String[] args) {
try {
DemoTable window = new DemoTable();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
} /**
* Open the window
*/
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} /**
* Create contents of the window
*/
protected void createContents() {
shell = new Shell();
shell.setLayout(new FillLayout());
shell.setSize(500, 375);
shell.setText("Demo"); table = new Table(shell, SWT.FULL_SELECTION | SWT.BORDER);
table.addMouseListener(new MouseAdapter() {
public void mouseDown(final MouseEvent e) {
TableItem[] selected = table.getSelection();
if (selected.length > 0)
{
TableItem current = selected[0];
String row_data = "";
for (int i = 0; i < table.getColumnCount(); i++)
{
row_data += current.getText(i)+" ";
}
MessageDialog.openInformation(shell,"Row Data",row_data);
}
}
});
table.setLinesVisible(true);
table.setHeaderVisible(true); final TableColumn nameCol = new TableColumn(table, SWT.NONE);
nameCol.setWidth(237);
nameCol.setText("Name"); final TableColumn homeCol = new TableColumn(table, SWT.NONE);
homeCol.setWidth(147);
homeCol.setText("Home"); final TableColumn ageCol = new TableColumn(table, SWT.NONE);
ageCol.setWidth(100);
ageCol.setText("Age"); final TableItem r1 = new TableItem(table, SWT.BORDER);
String[] row = {"David Chan","Hubei","20"};
r1.setText(row);
final TableItem r2 = new TableItem(table, SWT.BORDER);
row = new String[]{"Joe Wang","Anhui","30"};
r2.setText(row);
//
}}