Which is the Best Java Web Framework ?

Java SWT / JFace - Delete KeyPress Listener - KeyListener - Code Snippet


1.  Code Snippet to associate a Delete Key Listener to a treeViewer.

class DeleteKeyListener implements KeyListener
 {
        @Override
      public void keyPressed(KeyEvent e) {
           if (e.keyCode == SWT.DEL) {
     
           }
        }

        @Override
         public void keyReleased(KeyEvent e) {
   
 }
 }

[widgetObj].addKeyListener(new DeleteKeyListener ());

For ex - treeViewer.addKeyListener(new DeleteKeyListener ());

2. Complete Code Snippet for implementing a Delete Key Listener to Delete a table or tree row.

class DeleteModifierKeyListener implements KeyListener
    {
        @Override
      public void keyPressed(KeyEvent e) {
      if (e.keyCode == SWT.DEL) {
      IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
      if (selection.isEmpty()) {
      return;
      } else {
                       TreeItem[] items = treeViewer.getTree().getSelection();
                           for (TreeItem treeItem : items)
                                       {
                                                list.remove(treeItem.getData());
                                       }
                                          treeViewer.refresh();
                        }
            }
       }

       @Override
public void keyReleased(KeyEvent e) {
 // TODO Auto-generated method stub
}
    }





Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.