How to detect double mouse click in table cell? [message #463351] |
Fri, 04 November 2005 00:39  |
Eclipse User |
|
|
|
Originally posted by: siegfried.heintze.com
The following code works with a single click. How do I modify it so my
listener only executes when a single table cell has been double clicked?
I tried adding a MouseListener but that will only give me coordinates and
not the contents of the table cell. If I have coordinates, how do I get the
table cell contents?
Thanks,
Siegfried
table = new Table(this, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
data = new FormData();
data.top = new FormAttachment(0, 0);
data.bottom = new FormAttachment(100, 0);
data.left = new FormAttachment(sash, 0);
data.right = new FormAttachment(100, 0);
table.setLayoutData(data);
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent event){
if(table.getSelectionCount()==1){
TableItem item =table.getSelection()[0];
String urlTarget = item.getText();
}
}
});
new TableColumn(table, 0).setText("Name");
new TableColumn(table, 1).setText("Value");
new TableColumn(table, 2).setText("Text");
|
|
|
|
|
|
Re: How to detect double mouse click in table cell? [message #463371 is a reply to message #463369] |
Fri, 04 November 2005 11:39  |
Eclipse User |
|
|
|
> That worked! Now, why is it that getSelection returns me an array of 1? I
> can only get the contents of the first column! How do I get the second
> column?
The TableItem you receive from getSelection contains every column and you
get the contents of each one with getText(int).
This is only a guess as I havent done this myself and I dont know why you
want the column contents anyway. The SWT table is remarkable low level and
your data should be stored in a model. Then you need a class which can
convert your model object to a string suitable for a table column and a
class to put these strings into the table. When a row is selected get the
index of the row and resolve it back to your domain object in your model.
I will abandon the Table in favor of TableViewer and hope it is easier to
manage.
Ricky
|
|
|
Powered by
FUDForum. Page generated in 0.11410 seconds