按钮滚动多个微调器,当我希望它只滚动一个

时间:2018-01-17 08:33:02

标签: button javafx spinner scenebuilder actionevent

public class ManageSpinners implements Initializable {

@Override
public void initialize(URL location, ResourceBundle resources) {
lettersValueFactory = new 
SpinnerValueFactory.ListSpinnerValueFactory<String>
(lettersValuesObservList);
lettersValueFactory.setValue("A");
charValueFactory = new 
SpinnerValueFactory.ListSpinnerValueFactory<String>
(charValuesObservList);
charValueFactory.setValue("!");

 spinOne=new Spinner(lettersValueFactory)
 spinOneEditor = spinOne.getEditor();
 spinOne.valueProperty().addListener(new ChangeListener() {
  @Override
  public void changed(ObservableValue observable, Object oldValue, 
  Object newValue) {
      spinOneEditor.setText(spinOne.getValue().toString());
      spinOneEditor.commitValue();
     }
  });

  spinTwo=new Spinner(charValueFactory);
  spinTwoEditor = spinTwo.getEditor();
  spinTwo.valueProperty().addListener(new ChangeListener() {
  @Override
  public void changed(ObservableValue observable, Object oldValue, 
   Object newValue) {
     spinTwoEditor.setText(spinTwo.getValue().toString());
     spinTwoEditor.commitValue();
   }
 });

  buttonOne.setOnMouseClicked(new EventHandler<MouseEvent>() {
  @Override
  public void handle(MouseEvent event) {
    spinOne.increment();
    }
  });

  buttonTwo.setOnMouseClicked(new EventHandler<MouseEvent>() {
  @Override
  public void handle(MouseEvent event) {
    spinTwo.increment();
    }
  });
 }
}

当我按下按钮时......两个Spinners都会递增,只有spinOne才会递增(根据代码);并且当按下按钮2时,两个旋转器都递增。我想只有一个按钮控制一个微调器。 错误在哪里?

0 个答案:

没有答案