|
15 | 15 | import javafx.scene.control.MenuItem; |
16 | 16 | import javafx.scene.control.*; |
17 | 17 | import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory; |
| 18 | +import javafx.scene.control.SpinnerValueFactory.DoubleSpinnerValueFactory; |
18 | 19 | import javafx.scene.control.TableColumn.CellEditEvent; |
19 | 20 | import javafx.scene.control.cell.MapValueFactory; |
20 | 21 | import javafx.scene.control.cell.TextFieldListCell; |
@@ -161,14 +162,38 @@ public static void setSpinnerValueFactory(Spinner<Integer> spinner, int min, int |
161 | 162 | setSpinnerValueFactory(spinner, min, max, initialValue, 1); |
162 | 163 | } |
163 | 164 |
|
164 | | - public static void setSpinnerValueFactory(Spinner<Integer> spinner, int min, int max, int initialValue, |
165 | | - int amountToStepBy) { |
166 | | - IntegerSpinnerValueFactory secondStart_0svf = new SpinnerValueFactory.IntegerSpinnerValueFactory(min, max, |
167 | | - initialValue, amountToStepBy); |
168 | | - spinner.setValueFactory(secondStart_0svf); |
169 | | - spinner.getEditor().textProperty().addListener((observable, oldValue, newValue) -> { |
170 | | - spinner.getValueFactory().setValue(Integer.parseInt(newValue)); |
171 | | - }); |
| 165 | + public static void setSpinnerValueFactory(Spinner<Double> spinner, double min, double max) { |
| 166 | + setSpinnerValueFactory(spinner, min, max, min, 1d); |
| 167 | + } |
| 168 | + |
| 169 | + public static void setSpinnerValueFactory(Spinner<Double> spinner, double min, double max, double initialValue) { |
| 170 | + setSpinnerValueFactory(spinner, min, max, initialValue, 1d); |
| 171 | + } |
| 172 | + |
| 173 | + public static void setSpinnerValueFactory(Spinner spinner, Number min, Number max, Number initialValue, Number amountToStepBy) { |
| 174 | + if (min instanceof Integer) { |
| 175 | + IntegerSpinnerValueFactory secondStart_0svf = new IntegerSpinnerValueFactory((int) min, (int) max, (int) initialValue, (int) amountToStepBy); |
| 176 | + spinner.setValueFactory(secondStart_0svf); |
| 177 | + spinner.getEditor().textProperty().addListener((observable, oldValue, newValue) -> { |
| 178 | + try { |
| 179 | + spinner.getValueFactory().setValue(Integer.parseInt(newValue)); |
| 180 | + } catch (Exception e) { |
| 181 | + log.warn("数字int转换异常 newValue:" + newValue); |
| 182 | + spinner.getEditor().setText(oldValue); |
| 183 | + } |
| 184 | + }); |
| 185 | + } else if (min instanceof Double) { |
| 186 | + DoubleSpinnerValueFactory secondStart_0svf = new DoubleSpinnerValueFactory((double) min, (double) max, (double) initialValue, (double) amountToStepBy); |
| 187 | + spinner.setValueFactory(secondStart_0svf); |
| 188 | + spinner.getEditor().textProperty().addListener((observable, oldValue, newValue) -> { |
| 189 | + try { |
| 190 | + spinner.getValueFactory().setValue(Double.parseDouble(newValue)); |
| 191 | + } catch (Exception e) { |
| 192 | + log.warn("数字double转换异常 newValue:" + newValue); |
| 193 | + spinner.getEditor().setText(oldValue); |
| 194 | + } |
| 195 | + }); |
| 196 | + } |
172 | 197 | } |
173 | 198 |
|
174 | 199 | /** |
|
0 commit comments