[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] Re: [Q] Table getValueAt(int row, int col), addMouseMotionListener and table contents update/repaint?

Valentino,

The example that you refer to (
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/snippits/snippet3.html
) will work in any column.  If it's not working for you then your table
probably does not have the SWT.FULL_SELECTION style bit.  Without this bit
then only column 0 is selectable.

If you think that this should change then you can log a feature request
with Platform - SWT.

Grant

Valentino Kyriakides wrote:

> I wonder if some deeply needed access method  might be missing in the Table
> or TableItem classes. I miss here something like  "int
> table.rowAtPoint(Point p)", "int table.columnAtPoint(Point p)", which would
> allow to implement something like "Object getValueAt(int row, int col)".

> For example in Swing's JTable you can get the exact particular row and
> column values via a "Point p" e.g.:


> ----------- Swing JTable example fragments -----------------
> ....
> table.addMouseListener(new MouseHandler());
> table.addMouseMotionListener(new MouseHandler());
> ....

> class MouseHandler extends MouseInputAdapter {
>   public void mouseMoved(MouseEvent evt) {
>      Point p = evt.getPoint();
>       int row = table.rowAtPoint(p);
>       int column = table.columnAtPoint(p);
>       if (row == -1 || column == -1) {
>         status.setText(" ");
>       }
>       else {
>         String ch = (String) table.getModel().getValueAt(row, column);
>         ...
>         ...
>       }
>   }

>  public void mouseClicked(MouseEvent evt) {
>       Point p = evt.getPoint();
>       int row = table.rowAtPoint(p);
>       int column = table.columnAtPoint(p);
>      ...
>   }
> ....
> }

> class MyTableModel extends AbstractTableModel {
>     public int getColumnCount() {
>       return columnCount;
>     }

>     public int getRowCount() {
>       return rowCount;
>     }

>     public Object getValueAt(int row, int col) {
>           return new String(new byte[] { (byte) (row * getRowCount() +
> col) }, ourString);
>     }

> ----------- EOF Swing JTable example fragments -----------------


> In contrast here for JFace/SWT, I've only seen the following example, which
> would only popup a message dialog for the first clicked column item of a row
> (column 0 of row y). But this way it isn't capable of reacting in a general
> manner on (column x of  row y):

>  theTable.addListener (SWT.MouseDown, new Listener () {
>   public void handleEvent (Event event) {
>    Point pt = new Point (event.x, event.y);
>    TableItem item = theTable.getItem (pt);
>    if (item == null) return;
>    for (int i=0; i < 16; i++) {
>     Rectangle rect = item.getBounds (i);
>      if (rect.contains (pt)) {
>         int index = theTable.indexOf (item);
>         showMessage("Int: " + index + "-" + i);
>     }
>    }
>   }
>  });


> So what's the right way (for say a N x M Table) to get the table value of a
> particular (row, col) back, which is clicked, hovered over with or selected
> with the mouse?

> 1  2   3
> 4 [5] 6
> 7  8   9

> And whats the prefered/best way, to dynamically change a whole tables
> contents (for an N x M table all of it's row, col entries) with a repaint?


> -Valentino