TextArea不处理MouseEvent.MOUSE_PRESSED [英] TextArea does not handle MouseEvent.MOUSE_PRESSED
问题描述
我正在构建一个 JavaFX
应用程序,我插入了 TextArea
。
TextArea
分配了 CSS
类(不知道是否重要):
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;
}
有关于此<$ c的2个问题$ c> TextArea :
-
-fx-cursor:default;
无效,因为光标仍然是文本光标。这很奇怪,因为我使用相同的类来获得具有正确/预期结果的TextField
-
TextArea不处理
MOUSE_PRESSED
event
我的代码是:
-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 resultsThe 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);
}
});
任何想法为什么?
我想注意当我更改 EventHanler
来处理 MOUSE_CLICKED
所有内容很好
推荐答案
我怀疑TextArea上鼠标事件的默认处理程序在它到达你的处理程序之前消耗了鼠标按下的事件。
I suspect the default handlers for mouse events on the TextArea are consuming the mouse pressed event before it gets to your handler.
改为安装EventFilter:
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.
对于你的css问题,请尝试
For your css issue, try
.default-cursor .content {
-fx-cursor: default ;
}
这篇关于TextArea不处理MouseEvent.MOUSE_PRESSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!