Issue
I am building a JavaFX
application and I have a TextArea
inserted.
The TextArea
has a CSS
class assigned (don't know if it matters):
.default-cursor{
-fx-background-color:#EEEEEE;
-fx-cursor:default;
}
There are 2 issues about this TextArea
:
-fx-cursor:default;
Has no effect as the cursor remains the text cursor. That is weird as i use the same class for aTextField
with proper/expected results- The TextArea does not handle
MOUSE_PRESSED
event
My code is :
textArea.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
System.out.println("print message");
}
});
Any ideas why?
I want to note that when I changed EventHandler
to handle MOUSE_CLICKED
everything is fine
Solution
I suspect the default handlers for mouse events on the TextArea are consuming the mouse pressed event before it gets to your handler.
Install an EventFilter instead:
textArea.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
System.out.println("mouse pressed");
}
});
The Event filter will get processed before the default handlers see the event.
For your css issue, try
.default-cursor .content {
-fx-cursor: default ;
}
Answered By - James_D