Results 1 to 2 of 2
Thread: Table selection listener
- 01-13-2011, 04:21 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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();
}
- 01-16-2011, 10:35 AM #2
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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
-
Selection in JTable
By tremon in forum JDBCReplies: 1Last Post: 06-11-2010, 09:57 PM -
How to repaint.refresh the table (table model) with combo box selection envent
By man4ish in forum AWT / SwingReplies: 1Last Post: 01-08-2010, 07:19 AM -
Key selection for SSL/TLS
By OrangeDog in forum Advanced JavaReplies: 3Last Post: 04-27-2009, 11:38 PM -
table selection in SWT/Jface
By amine2610 in forum SWT / JFaceReplies: 1Last Post: 04-15-2009, 09:38 PM -
Code for selection
By kneekow in forum EclipseReplies: 0Last Post: 02-01-2008, 04:10 PM
Bookmarks