Results 1 to 2 of 2
  1. #1
    leda is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default Table selection listener

    Im calling selection table.setSelection and nothing happens.
    why isnt the listener responding?

    public class Table2 {

    static private Table table;

    public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    table = new Table(shell, SWT.BORDER | SWT.SINGLE);
    TableColumn column = new TableColumn(table, SWT.NONE);
    column.setWidth(100);
    for (int i = 0; i < 1000; i++) {
    TableItem item = new TableItem(table, SWT.NULL);
    item.setText("Item " + i);
    }

    table.addSelectionListener(new SelectionAdapter() {

    public void widgetSelected(SelectionEvent e) {
    int i = table.getSelectionIndex();
    if (i < 0)
    return;
    // synchronize contact details with the selected contact
    System.out.println("hello"+i);
    }
    });


    table.setSize(200, 200);

    table.setSelection(5); // <<<<===============
    //table.notifyListeners(SWT.Selection, null); THIS HALPES!!!!!!!


    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
    }

  2. #2
    leda is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default found the answer myself

    Q: Why are some events like Selection not fired in response to programmatic widget changes?
    A: This is a design decision that was made in order to minimize notification of potentially unwanted events. For example, when the selection of a control is changed programmatically, SWT does not issue a selection event. If this were not the case then changing the selection multiple times would send multiple notifications and run application listener code multiple times, thereby leading to a potential performance problem. Clients that wish to notify widget listeners of changes made programatically can do so by creating an Event object and invoking Widget.notifyListeners(int, Event) on the widget. Note that some programmatically-triggered events are sent, typically in response to low-level widget operations such as focus, move and resize changes.

Similar Threads

  1. Selection in JTable
    By tremon in forum JDBC
    Replies: 1
    Last Post: 06-11-2010, 09:57 PM
  2. Replies: 1
    Last Post: 01-08-2010, 07:19 AM
  3. Key selection for SSL/TLS
    By OrangeDog in forum Advanced Java
    Replies: 3
    Last Post: 04-27-2009, 11:38 PM
  4. table selection in SWT/Jface
    By amine2610 in forum SWT / JFace
    Replies: 1
    Last Post: 04-15-2009, 09:38 PM
  5. Code for selection
    By kneekow in forum Eclipse
    Replies: 0
    Last Post: 02-01-2008, 04:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •