Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
JavaFX - Mostrar cuadro de diálogo de alerta dentro del evento ChangeListener

Quiero mostrar un cuadro de diálogo de alerta cuando se cambia el valueProperty de un spinner. Por lo tanto, agregué un ChangeListener a mi valueProperty:

 this.spinnerColumns.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(2,20)); this.spinnerColumns.getValueFactory().valueProperty().addListener((observable, oldValue, newValue) -> { if(oldValue > newValue) { // Ask for permission System.out.println("Ask for permission"); Alert alert = new Alert(Alert.AlertType.WARNING); alert.setTitle("Error"); alert.setHeaderText("Ask something..."); alert.showAndWait(); if(alert.getResult() == ButtonType.OK) { // do something } } });

Este código no funciona correctamente. Cuando se muestra la Alerta, la rueda giratoria sigue disminuyendo su valor hasta que se alcanza el valor mínimo. Algunas sugerencias de cómo hacer esto?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Hasta donde yo sé, es difícil dejar de girar sin usar la reflexión... Prueba este código.

 if(oldValue > newValue) { try { Skin<?> skin = this.spinnerColumns.getSkin(); Object behavior = skin.getClass().getMethod("getBehavior").invoke(skin); behavior.getClass().getMethod("stopSpinning").invoke(behavior); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); return; // If refleciton failed, do nothing } // Ask for permission
over 4 years ago · Santiago Trujillo Report

0

Parece el error JDK-8089332 y es similar al error JDK-8252863 . La solución allí conduce a:

 this.spinnerColumns.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(2, 20)); this.spinnerColumns.getValueFactory().valueProperty().addListener((observable, oldValue, newValue) -> { Node increment = spinnerColumns.lookup(".increment-arrow-button"); if (increment != null) { increment.getOnMouseReleased().handle(null); } Node decrement = spinnerColumns.lookup(".decrement-arrow-button"); if (decrement != null) { decrement.getOnMouseReleased().handle(null); } if (oldValue > newValue) { // Ask for permission System.out.println("Ask for permission"); Alert alert = new Alert(Alert.AlertType.WARNING); alert.setTitle("Error"); alert.setHeaderText("Ask something..."); alert.showAndWait(); if (alert.getResult() == ButtonType.OK) { // do something } } });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!