0

I have TableView and I want my program to doSomething() when user clicks on a cell. After searching on Internet (stackoverflow included), I found this.

Tried that method, but I got a compile error on these code :

EventHandler click = new EventHandler() {
    public void handle(MouseEvent t) {
        System.out.println("CLICKED");
    }
};

NetBeans asked me to override all abscract method, so I did it.

EventHandler click = new EventHandler() {
    @Override
    public void handle(MouseEvent t) {
        System.out.println("CLICKED");
    }
};

Still got same error :

error: method does not override or implement a method from a supertype

If I remove @Override annotation, I got :

error: <anonymous pengamatan.penginderaan.FXMLDocumentController$4> is not abstract and does not override abstract method handle(Event) in EventHandler

Any help? Thank you.

panoet
  • 3,608
  • 1
  • 16
  • 27

2 Answers2

2

You can try:

cell.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
    @Override
    public void handle(MouseEvent event) {
         System.out.println("cell clicked!");
    }
});

found here

Community
  • 1
  • 1
  • I have read that and I imagine how if I have lots of cells, so I am looking for another way. As described http://monkeyhash.wordpress.com/2011/10/20/javafx-2-0-table-click-events/ , I can use CellFactory class to do that. I tried that but get an error. – panoet Mar 17 '14 at 11:52
-4

Found the solution! Here is the code :

....
import javafx.scene.input.MouseEvent;
....
....
EventHandler click = new EventHandler<MouseEvent>() {
@Override
    public void handle(MouseEvent t) {
        if(t.getClickCount()>1) {
        System.out.println("DOUBLE CLICK");
        }
    }
};
....

Hope it helps. Thank you.

panoet
  • 3,608
  • 1
  • 16
  • 27