[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Table issue

dnise wrote:
Shawn Spiars wrote:

dnise wrote:
Shawn Spiars wrote:

eclipse.org
Hi
Thanks you advice . but i can't find what i want .assume as follow it's
a table
------------------------------------
| column1 | column2 | column3 |
|-----------------------------------
| ff1 | ff2 | ff3 |
------------------------------------
| kk1 | kk2 | kk3 |
------------------------------------


we can select a row  when i click. we can use follow codes to get
TableItem TableItem [] tableItem=table.getSelection();
we can add some Listeners for this tableItem. But it doesn't complete
what i
want.    we can select a row when i click on ff1 ãff2ãff3ãkk1ãkk2 or kk3.
the function which i want to implement is that trigger some event when i
click on ff3 or kk3  but not ff1,ff2,kk1,kk2.
can i implement it?

thanks

best regards

dnise

You might try using a mouseListener on the table and then determining the selected cell using the mouseUp event. See snippet below.

table = toolkit.createTable(parent,
SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);


table.addMouseListener(new MouseAdapter() { public void mouseUp(MouseEvent event) { Point point = new Point(event.x, event.y); TableItem item = table.getItem(point);

if (item != null) {
int columnCount = table.getColumnCount();
for (int i=0; i < columnCount; i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(point)) {
System.out.println("table item column: " + i);
System.out.println("table item: " + item.getText(i));
                   }
                 }
         }
   }
});



Hi:
Thanks for you replying . I can implement this for the moment. According to
your code,it got position of column that i wanted to operate. if the column
fixed or the column counts doesn't change, i can finished . but if the
column counts changed ,for example ,in my application, users get
information on the basis of theirs authorization. So sometimes it would
display 4 columns, sometimes show 3 columns. i can set the operation
column at last in table ,the mainly cause is column index has been
changed. could i get the last column position while the column counts changed?


Thanks & regards

dnise


First, I must agree with Tom's reply - the best way to do this is with JFace-Viewers and a CellEditor. Back to your question - I am not sure I understand. If you are saying that the last column in the selected row is always the column you want then the solution is simpler. You could use a selectionListener and do something like this:

table.addSelectionListener(new SelectionAdapter() {
  public void widgetSelected(SelectionEvent event) {

TableItem item = (TableItem) event.item;
int columnCount = table.getColumnCount();
System.out.println("last column value: " + item.getText(columnCount-1));


  }
});

Shawn