[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Counting click events in a TableColumn??

The TableHeader only supports a very small number of events currently.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=17871 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=32322

Tom

Frank schrieb:
I wonder how, too.
I find adding selectionListener or MouseListener doesn't work.


"Tim Molter" <tim.molter@xxxxxxxxx> wrote in message news:4711c0324846e1c613e936165be72e73$1@xxxxxxxxxxxxxxxxxx
Hi. Is it possible to count the number of times a column header in a table has been clicked? Following is a working snippet that I'm using to create a table with two columns. What can I put in the handleEvent method so that a counter is incremented each time it's triggered? I'm guessing that I need to create some kind of "global" counter variable outside handleEvent that is incremented inside the handleEvent method, but I'm not exactly sure how to do that. Any tips??!!

Thanks much!


import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.*;

public class ColumnEventCount {


public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER); table.setHeaderVisible(true); int columnCount = 2; TableColumn[] tableColumns = new TableColumn[columnCount]; for (int m = 0; m < columnCount; m++){ //create the columns tableColumns[m]= new TableColumn(table, SWT.CENTER); tableColumns[m].setText("column" + Integer.toString(m)); tableColumns[m].setWidth(100); tableColumns[m].addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) {

    }
});
}

   TableItem item = new TableItem(table, SWT.NONE);
   item.setText(new String[] { "Larry", "King",});
   item = new TableItem(table, SWT.NONE);
   item.setText(new String[] { "Al", "Bundy"});

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





--
B e s t S o l u t i o n . at
--------------------------------------------------------------------
Tom Schindl                                          JFace-Committer
--------------------------------------------------------------------