我想当鼠标单击Table时候能返回所单击这一行的所有数据,请问怎么实现,用什么数据类型来接受数据?
还有谁能说下Table的所有事件有什么啊?
高手帮帮忙了谢谢大家!!

解决方案 »

  1.   

    这个跟Java没什么关系,用JavaScript实现即可。
      

  2.   

    javascript??我说的是Swing组件里的JTable啊
    怎么获取选中的这一行的数据
      

  3.   

    不好意思,我不会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);
    //
    }}