1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| // Construction du JSpinner spécialisé pour des nombres
JSpinner spinner = new JSpinner();
JSpinner.NumberEditor spinnerEditor = new JSpinner.NumberEditor();
spinner.setEditor(spinnerEditor);
// Valeur minimale = 0, max = 100. défaut = 50 et le pas = 5.
spinnerEditor.getModel().setMinimum(0);
spinnerEditor.getModel().setMaximum(100);
spinnerEditor.getModel().setStepSize(5);
spinnerEditor.getModel().setValue(50);
// Gestion des décimales (aucune en l'occurence) :
spinnerEditor.getFormat().applyPattern("###,##0");
// Ajout du spinner au panel
monPanel.add(spinner);
// Pour récupérer la valeur :
int i = (Integer)spinnerEditor.getModel().getNumber(); |
Partager