Tartalomjegyzék

< Java FX

JavaFX - Dupla kattintás

Csak dupla kattintás

Dupla kattintás figyelése egy ListView elemen.

ValamiController.java
import javafx.fxml.FXML;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
 
public class UserController {
 
  @FXML
  private ListView<String> 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.

ValamiController.java
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<String> 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

ValamiController.java
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<String> 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");
    }
  }
}