[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??
|
Oh, I know how,
Add SelectionListener to the each TableItem. If the header clicks once, then
the counter increase by one.
hehe, have fun.
"Frank" <frank@xxxxxxxxxxx> wrote in message
news:fhrgi1$v2c$1@xxxxxxxxxxxxxxxxxxxx
>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();
>> }
>> }
>>
>
>