Andrey Redkovskiy
Andrey Redkovskiy

Reputation: 25

How to create "deselecting" listener on SWT Java

Well, I have a table with users data and the button to change selected user. There is a listener on this table:when I doubleclick the table item my button becomes enabled(because needed user appeared). The question is how to create a listener on my table, which will detect that there are no selected items in my table, cause I want to make my button disabled again.

table_1.addMouseListener(new MouseListener() {
            public void mouseUp(MouseEvent e) {}

            public void mouseDown(MouseEvent e) {}

            public void mouseDoubleClick(MouseEvent e) {
                // TODO Auto-generated method stub
                btnNewButton_3.setEnabled(true);
            }

Upvotes: 0

Views: 129

Answers (1)

greg-449
greg-449

Reputation: 111142

Use the table selection listener:

table_1.addSelectionListener(new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {
      int selCount = table_1.getSelectionCount();

      // TODO selCount will be 0 if nothing is selected
    }
});

Upvotes: 1

Related Questions