OVH Cloud OVH Cloud

largeurJspinner

3 réponses
Avatar
D. Malik
je cherche à augmenter la largeur du JSpinner
quoi que je fasse c'est pareil

je souhaite rendre visible le nombre "-1.5"
Soit je vois le "-" soit je vois le 5 mais pas les 2
Mais n'y aurait-il pas une autre erreur avec le SpinnerNumberModel qui veut
en paramètre des entiers et la variable cotrPlan est un décimal !
Je m'y perd et je fatigue.
Je vais donc aller manger, c'est l'heure !


Voici la partie de code concernée
[code]
containerPlan= new JPanel();
containerPlan.setLayout(new GridBagLayout());
GridBagConstraints affichePlan = new GridBagConstraints();
containerPlan.setBackground(couleur6);
affichePlan.insets= new Insets(0,0,2,0);

affichePlan.gridwidth=GridBagConstraints.REMAINDER;
containerPlan.add(new Label (" Afficher un Plan
Horizontal"),affichePlan);

affichePlan.gridwidth=GridBagConstraints.REMAINDER;
modeAffichePlan = new CheckboxGroup();

ouiPlanCheckbox = new Checkbox ("Oui", modeAffichePlan, false);
nonPlanCheckbox = new Checkbox ("Non", modeAffichePlan, true);

affichePlan.gridwidth=GridBagConstraints.RELATIVE;
containerPlan.add(ouiPlanCheckbox,affichePlan);

affichePlan.gridwidth=GridBagConstraints.REMAINDER;
containerPlan.add(nonPlanCheckbox,affichePlan);

cotePlan=1;
affichePlan.gridwidth=GridBagConstraints.RELATIVE;
containerPlan.add(new Label ("d'équation z="));

final JSpinner cotePlanSpinner =new JSpinner(new
SpinnerNumberModel(cotePlan, -2, 2, 0.1));
cotePlanSpinner.setMinimumSize(new Dimension(20,10));

cotePlan=((Number) cotePlanSpinner.getValue()).intValue();
affichePlan.gridwidth=GridBagConstraints.REMAINDER;
containerPlan.add(cotePlanSpinner,affichePlan);
containerPlan.setBackground(couleur7);
containerPlan.setBorder(BorderFactory.createLineBorder(Color.green));
[/code]

MERCI
Daniel

3 réponses

Avatar
Régis Troadec
Salut,

"D. Malik" a écrit dans le message de news:
bvdgek$56d$

final JSpinner cotePlanSpinner =new JSpinner(new
SpinnerNumberModel(cotePlan, -2, 2, 0.1));
cotePlanSpinner.setMinimumSize(new Dimension(20,10));


Ne serait-ce pas la présence du modificateur "final" ?

a+, regis

Avatar
Régis Troadec
Re,

Mais n'y aurait-il pas une autre erreur avec le SpinnerNumberModel qui
veut

en paramètre des entiers et la variable cotrPlan est un décimal !


Le constructeur SpinnerNumberModel peut aussi prendre des double (type
primitif), mais aussi des objets de type Number et de types implémentant
Comparable (les classes *equivalentes* aux types primitifs)

final JSpinner cotePlanSpinner =new JSpinner(new
SpinnerNumberModel(cotePlan, -2, 2, 0.1));


double cotePlan = 1.0;

JSpinner cotePlanSpinner = new JSpinner(new
SpinnerNumberModel(cotePlan,-2.0,2.0,0.1));

// ou meme la classe Double (implémente l'interface Comparable)
Double cotePlan = new Double(1.0);
Double mini = new Double(-2.0);
Double maxi = new Double(2.0);
Double pas = new Double(0.1);
JSpinner cotePlanSpinner = new JSpinner(new
SpinnerNumberModel(cotePlan,mini,maxi,pas));

//Sans le modificateur final, setMinimumSize() doit marcher
cotePlanSpinner.setMinimumSize(new Dimension(20,10));
cotePlan=((Number) cotePlanSpinner.getValue()).intValue();


cotePlan = cotePlanSpinner.getNumber()).doubleValue();

Avatar
Daniel MALIK
Ca marche avec :

double cotePlan =1.0;
double mini =-2.01;
double maxi =2.01;
double pas = 0.1;

affichePlan.gridwidth=GridBagConstraints.RELATIVE;
containerPlan.add(new Label ("d'équation z="));

JSpinner cotePlanSpinner =new JSpinner(new
SpinnerNumberModel(cotePlan,mini,maxi,pas));

//cotePlanSpinner.setMinimumSize(new Dimension(20,10));

cotePlan = ((Number)cotePlanSpinner.getValue()).doubleValue();