I have a TextArea, and have been set a handler for the scroll event:
myTextarea.setOnScroll((event) -> {
System.out.println("setOnScroll: " + event);
});
But I found when the text in the textarea are very long, and if I put my mouse on it and scroll the mouse wheel, it doesn't print the event!
Only if the text reaches to the end, it starts to show the event.
I also tried setOnScrollStarted, and setOnScrollFinished, the same situation happens.
How to capture each scroll event in JavaFX?
Finally I found the solution:
myTextarea.addEventFilter(ScrollEvent.ANY, (x) -> {
System.out.println("scrolled");
});
Seems a little strange to use the method addEventFilter, but it works.
Related
I am trying to make an animation where a text field an some buttons appear when I press a toggle button, and when I press the toggle button again, it disappears. I have almost succeeded in, but each time I press the toggle button, the toggle menu moves further and further to the right. I'm not that good at explaining, but I made a little gif so you can see. https://gyazo.com/1bd43a95ec988edbce47704674c46418
Hope someone can help me! It is in the method called "routeBtnAction"
The animation method
#FXML
private void routeBtnAction(){
if (routeBtn.isSelected()) {
searchbar.setPromptText("From");
TranslateTransition slideIn = new TranslateTransition();
slideIn.setDuration(Duration.millis(250));
slideIn.setCycleCount(1);
slideIn.setNode(routeMenu);
slideIn.setByX(173);
slideIn.setInterpolator(Interpolator.EASE_OUT);
slideIn.play();
} else {
searchbar.setPromptText("Search");
TranslateTransition slideOut = new TranslateTransition();
slideOut.setDuration(Duration.millis(300));
slideOut.setCycleCount(1);
slideOut.setNode(routeMenu);
slideOut.setByX(-routeMenu.getWidth());
slideOut.setInterpolator(Interpolator.EASE_IN);
slideOut.play();
}
}
I found out. It's supposed to be setToX, not setByX! :)
If I tap on radlistview items - it catches events, but if I tap on empty space at the bottom of radlistview - then silence.
Thanks for any help!
You need to set (tap) and (itemTap) for RadListView.
<RadListView [items]="countries" (itemTap)="onItemTap($event)" (tap)="tapOutSide($event)">
and in your .ts file
public onItemTap(args) {
console.log("Item Tapped at cell index: " + args.index);
}
public tapOutSide($event) {
console.log("TAPPED EMPTY SPACE");
console.log($event.object);
}
P.S. From the Screenshot, it looks like an Android phone and above solution works fine on Android. For ios, there is an open issue with nativescript.
I receive a Leave Event every time i move a pixel with my mouse over a customized QFrame i did. Why is this happening?.
I reimplemmented the leave and enter event as follows. As you can see i tried to comment the QFrame enterEvent, and restrict the repetition with a boolean, but it doesnt work because an enter and leave are continuously generated:
void enterEvent( QEvent *event ){
//QFrame::enterEvent(event);
if (!mouseHover_)
{
mouseHover_ = true;
emit hoverInSignal("");
}
}
void leaveEvent( QEvent *event ){
//QFrame::leaveEvent(event);
if (mouseHover_)
{
SmartUIWrapper::Instance()->addInfoMessage("out");
emit hoverOutSignal();
mouseHover_ = false;
}
}
Does it have something to be with the focus?
I discovered the reason.
I created a panel over this QFrame when i hovered.
When i moved the mouse, since the panel is positioned on the right bottom side of the cursor position, everytime i moved over the QFrame to the right or bottom, when i hovered this new panel i created, it looses the focus, so it gets closed again, then another hover comes, and then it´s created again... and again... everytime i hover the new panel.
My challenge is following situation:
I want to add an invisible (opacity 0) pane over the whole application, which receives all mouse and touch events. When an event occurs it resets some kind of activity timer.
My first approach (without such pane) was adding listeners to the root pane, which worked pretty well. But... the buttons consume all events, so the timer does not get reset.
In my opinion, the glasspane solution would be a much more nicer solution, but I can't find a solution to forward received mouse and touch events to the underlying controls.
In short: the pane intercepts a mouse event (trigger to reset timer), and the underlying button gets clicked.
Any ideas please?
EDIT first solution
I came to the solution to add an EventDispatcher to my root pane, which fires an custom event, when e.g. a mouse was pressed. So no glasspane, but it works:
//this == myRootPane
final EventDispatcher originalDispatcher = this.getEventDispatcher();
EventDispatcher dispatcher = new EventDispatcher() {
#Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {
if(timeoutResetEventHdlr != null) {
if(event instanceof MouseEvent) {
if(event.getEventType().equals(MouseEvent.MOUSE_PRESSED)) {
timeoutResetEventHdlr.handle(new PageTimeoutResetEvent());
}
}
}
originalDispatcher.dispatchEvent(event, tail);
return event;
}
};
this.setEventDispatcher(dispatcher);
Don't use a glass pane or muck around with the event dispatcher, use an event filter on the scene.
Filters are triggered in the event capturing phase, rather than the event bubbling phase, so you can intercept the event and take some action on it before the underlying controls consume the event.
I'm having five Image Buttons. If a button was clicked by mouse, then the button went to Onstate. Now if i pressed Space button it will zoom the button's image in a seperate Window.
The space button should not work when the button id in OFFstate. now can i trigger the Keyevent? i already referred Quicklook and working on that. any new ideas?
You don't need to trigger the key event, just respond to it as though it were any old method call from the button. After giving it a target and a selector, give it a key equivalent of #" " and respond to the key press accordingly:
- (void)someAction:(NSButton*)sender event:(NSEvent*)event {
//...
if ((sender.state == NSOnState) && (event.keyCode == 0x32)) {
//Zoom
}
//...
}