[[oktatas:programozás:java:java_fx|< Java FX]]
====== JavaFX - Dupla kattintás ======
* **Szerző:** Sallai András
* Copyright (c) 2024, Sallai András
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC BY-SA 4.0]]
* Web: https://szit.hu
===== Csak dupla kattintás =====
Dupla kattintás figyelése egy ListView elemen.
import javafx.fxml.FXML;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
public class UserController {
@FXML
private ListView userList;
@FXML
private void onListDoubleClick(MouseEvent e) {
if(
e.getButton().equals(MouseButton.PRIMARY) &&
e.getClickCount() == 2) {
System.out.println("Dupla");
}
}
}
===== Dupla kattintásra listaelem =====
Dupla kattintás figyelése egy ListView elemen.
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
public class UserController {
@FXML
private ListView userList;
@FXML
private void onListDoubleClick(MouseEvent e) {
if(
e.getButton().equals(MouseButton.PRIMARY) &&
e.getClickCount() == 2) {
System.out.println("Kattintott elem: " +
userList.getSelectionModel().getSelectedItem());
}
}
}
===== Egy és dupla kattintás szétválasztva =====
import java.io.IOException;
import javafx.animation.PauseTransition;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.util.Duration;
public class UserController {
PauseTransition pause = new PauseTransition(Duration.millis(500));
@FXML
private ListView userList;
@FXML
private TextField editField;
public UserController() {
pause.setOnFinished(e -> {
System.out.println("kattintott");
});
}
@FXML
private void onListDoubleClick(MouseEvent e) {
if (e.isPrimaryButtonDown() && e.getClickCount() == 1) {
pause.play();
}
if (e.isPrimaryButtonDown() && e.getClickCount() == 2) {
pause.stop();
System.out.println("dupla");
}
}
}