我正在构建一个 JavaFX
应用程序,并且插入了一个 TextArea
。
TextArea
分配了一个 CSS
类(不知道它是否重要):
.default-cursor{
-fx-background-color:#EEEEEE;
-fx-cursor:default;
}
TextArea
有两个问题:
-fx-cursor:default;
无效,因为光标仍然是文本光标。这很奇怪,因为我对具有正确/预期结果的TextField
使用相同的类- TextArea 不处理
MOUSE_PRESSED
事件
我的代码是:
textArea.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
System.out.println("print message");
}
});
有什么想法吗?
我想指出,当我更改 EventHandler
以处理 MOUSE_CLICKED
时,一切都很好
最佳答案
我怀疑 TextArea 上鼠标事件的默认处理程序在鼠标按下事件到达您的处理程序之前消耗了它。
改为安装 EventFilter:
textArea.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
System.out.println("mouse pressed");
}
});
事件过滤器将在默认处理程序看到事件之前得到处理。
对于你的css问题,试试
.default-cursor .content {
-fx-cursor: default ;
}
关于css - TextArea 不处理 MouseEvent.MOUSE_PRESSED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22348152/