IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AWT/Swing Java Discussion :

saisir un nombre maximal dans un JSpinner [Débutant(e)]


Sujet :

AWT/Swing Java

  1. #1
    Membre confirmé
    Inscrit en
    Août 2004
    Messages
    86
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 86
    Par défaut saisir un nombre maximal dans un JSpinner
    Bonjour,

    J'ai un champ Jspinner sur une interface en swing, ce champ accepte valeur minimal=1 et maximal=1000.
    je l'ai déclaré comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    JSpinner nombreASelectionnerField=new JSpinner(new SpinnerNumberModel(1, 1,
    				1000, 1));
    mais quand je saisie une valeur supérieure à 1000,il l'accepte!!!

    Pourriez vous SVP m'indiquer ue autre solution.

    Merci d'avance.

    Cdt,

  2. #2
    Membre émérite Avatar de jojodu31
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    875
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2008
    Messages : 875
    Par défaut
    es tu sur de ne pas faire un new JSpinner() ailleur ? normalement ça devrait marcher parfaitement

  3. #3
    Membre Expert
    Avatar de natha
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 346
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 346
    Par défaut
    +1
    Pour vérifier, déclare ton JSpinner en final éventuellement (provoquera une erreur de compilation si tu affectes le spinner à nouveau) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    final JSpinner nombreASelectionnerField=new JSpinner(new SpinnerNumberModel(1, 1, 1000, 1));
    Vérifie également si tu n'as pas un JSpinner déclaré en variable d'instance de la classe. Une bêtise dans le genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    JSpinner nombreASelectionnerField = new JSpinner();
     
    private void initComponents() {
        JSpinner nombreASelectionnerField=new JSpinner(new SpinnerNumberModel(1, 1, 1000, 1));
    }

  4. #4
    Membre confirmé
    Inscrit en
    Août 2004
    Messages
    86
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 86
    Par défaut listener
    Rebonjour,

    est ce qu'on peut déclarer un listener sur le JSpinner pour ajuster le nombre à1000 si l'utilisateur donne un nb>1000?

    merci d'avance

    Cdt,

  5. #5
    Membre émérite Avatar de jojodu31
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    875
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2008
    Messages : 875
    Par défaut
    oui :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    addChangeListener(this);
    et tu devra implémenter :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     public void stateChanged(ChangeEvent ce){
        int valeur = model.getNumber().intValue();
     
    }
    mais ce n'est pas la solution, ... tu devrais chercher d'où vient le pb je pense

  6. #6
    Membre Expert
    Avatar de natha
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 346
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 346
    Par défaut
    Citation Envoyé par coquero Voir le message
    est ce qu'on peut déclarer un listener sur le JSpinner pour ajuster le nombre à1000 si l'utilisateur donne un nb>1000?
    C'est du contournement... Tu vas rajouter du code pour corriger un comportement que tu as mal codé ailleurs. Dans ce nouveau code tu as une forte probabilité d'y ajouter au moins 1 bug, et ça te fera 2x plus de code à maintenir.
    Pourquoi faire simple quand on peut faire compliqué ?

    How to Use Spinners [en]

  7. #7
    Membre confirmé
    Inscrit en
    Août 2004
    Messages
    86
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 86
    Par défaut
    Bonjour,

    pour aapliquer addChangeListener sur le champ nombreASelectionnerField,

    dois je créer un modèle de SpinnerNumberModel,jusqu'à maintenant j'ai fait ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
     
     SpinnerNumberModel model = new SpinnerNumberModel(1, 1,
    				1000, 1); 
    Spinner nombreASelectionnerField = new JSpinner(model);
    nombreASelectionnerField.addChangeListener((ChangeListener) this);
    après j'ai implémenté

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    public void stateChanged(ChangeEvent ce) {
    		int valeur =model.getNumber().intValue();
    		if (valeur > 1000){
    			model.setValue(1000);
    		System.out
    				.println("Attention: vous ne pouvez pas dépasser 1000 ajout ");
    	}
    		else{
     
    		}
    	}

    J'aimerais que vous me disiez ce que je dois faire pas à pas surtout que je viens de toucher en swing.

    Merci bcp d'avance.

    Cdt,

  8. #8
    Membre émérite Avatar de jojodu31
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    875
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2008
    Messages : 875
    Par défaut
    tu dois faire un
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    if (valeur > 1000){
    			spinner.setValue(1000);
    pas un model.setValue

  9. #9
    Membre confirmé
    Inscrit en
    Août 2004
    Messages
    86
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 86
    Par défaut
    j'ai fait ce que vous me demandez mais je reçois le message

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: com.sncf.fret.swi.client.view.AddEditStatistiquesCriteresAjoutVoyageDialog cannot be cast to javax.swing.event.ChangeListener
    il n'accepte pas le cast:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     nombreASelectionnerField.addChangeListener((ChangeListener) this);
    cdt,

  10. #10
    Membre émérite Avatar de jojodu31
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    875
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2008
    Messages : 875
    Par défaut
    pas besoin de cast , il suffit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    spinner.addChangeListener(this);

  11. #11
    Membre Expert
    Avatar de natha
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 346
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 346
    Par défaut
    Bon arrête avec ce ChangeListener ! C'est n'importe quoi.
    Le code avec le SpinnerNumberModel fonctionne parfaitement, si ça ne fonctionne pas c'est que tu as une erreur quelque part, il ne sert à rien d'essayer de contourner le problème.

    Ce code fonctionne nikel :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.JButton;
    import javax.swing.JSpinner;
    import javax.swing.SpinnerNumberModel;
    import javax.swing.SwingUtilities;
     
    public class TestSpinner extends javax.swing.JFrame {
     
    	public static void main(String[] args) {
    		SwingUtilities.invokeLater(new Runnable() {
    			@Override
    			public void run() {
    				TestSpinner frame = new TestSpinner();
    				frame.setVisible(true);
    			}
    		});
    	}
     
    	public TestSpinner() {
    		SpinnerNumberModel model = new SpinnerNumberModel(1, 1, 10, 1);
    		JSpinner spinner = new JSpinner(model);
    		getContentPane().add(spinner, BorderLayout.CENTER);
    		getContentPane().add(createCloseButton(), BorderLayout.SOUTH);
    		pack();
    	}
     
    	private JButton createCloseButton() {
    		JButton button = new JButton("Fermer");
    		button.addActionListener(new ActionListener() {
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				System.exit(0);
    			}
    		});
    		return button;
    	}
     
    }
    On peut difficilement faire plus simple.

  12. #12
    Membre confirmé
    Inscrit en
    Août 2004
    Messages
    86
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 86
    Par défaut Programme global
    Merci jojodu31,natha

    tjs le même pb,quand l'utilisateur donne un nb<=1000 ça passe bien tandis que si nb>1000 ça fait rien,je voulais ajouter l'option que si le nb>1000 le nb redevient 1000.

    voici le code global
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
     
     
    public class AddEditStatistiquesCriteresAjoutVoyageDialog extends JPanel implements ChangeListener {
     
    	private static final long serialVersionUID = 1L;
    	public final static int ACCEPT_OPTION = 0;
    	public final static int CANCEL_OPTION = 1;
    	public final static String TEXT_ADD_TITLE = "Ajouter des voyages";
    	public final static String TEXT_ADD_SUBTITLE = "Ajout des voyages statistiques";
    	private final static String TEXT_GARE_VALIDATE_TOOLTIPS = "Double cliquer pour effacer";
    	private final static String TEXT_GARE_ERROR_TOOLTIPS = "Aucune gare séléctionnée";
    	private int returnValue;
    	private JSpinner nombreASelectionnerField;
    	private JLabel infoLabel;
    	private JPanel infoAreaPane;
    	private JTextField libelleClientOrigineField;
    	private JTextField libelleClientDestinataireField;
    	private JTextField codeUicOrigineField;
    	private JTextField codeUicDestinationField;
    	private JTextField codeGareOrigineField;
    	private JTextField codeGareDestinationField;
    	private JTextField codeLieuOrigineField;
    	private JTextField codeLieuDestinationField;
    	private JTextField libelleOrigineField;
    	private JTextField libelleDestinationField;
    	private JFormattedTextField debutPeriodeStatistiqueField;
    	private JFormattedTextField finPeriodeStatistiqueField;
    	private JFormattedTextField debutPeriodeOperationnelleField;
    	private JFormattedTextField finPeriodeOperationnelleField;
    	private AcceptAction acceptAction;
    	private CancelAction cancelAction;
    	private Action searchOrigineAction;
    	private Action searchDestinationAction;
    	private JDialogModel dialog;
    	private JTextArea infoArea;
    	private ILieu origine;
    	private ILieu destination;
    	private JRemoveLabel removeOrigineLabel;
    	private JRemoveLabel removeDestinationLabel;
    	private SpinnerNumberModel model;
     
    	public AddEditStatistiquesCriteresAjoutVoyageDialog() {
    		super(new BorderLayout());
    		initActions();
    		initComponents();
    		initComponentsAnnotations();
    		initEventHandling();
    		dialog = null;
    		this.add(buildContents(), BorderLayout.CENTER);
    	}
     
    	private void initActions() {
    		acceptAction = new AcceptAction();
    		cancelAction = new CancelAction();
    		searchOrigineAction = new SearchOrigineAction();
    		searchDestinationAction = new SearchDestinationAction();
     
    	}
     
    	private JPanel buildContents() {
    		FormLayout layout = new FormLayout("fill:default:grow",
    				"max(14dlu;pref), 6dlu, pref, 3dlu, pref");
     
    		PanelBuilder builder = new PanelBuilder(layout);
    		builder.setDefaultDialogBorder();
     
    		CellConstraints cc = new CellConstraints();
    		builder.add(buildInfoAreaPane(), cc.xy(1, 1));
    		builder.addSeparator("Informations", cc.xy(1, 3));
    		builder.add(buildEditorPanel(), cc.xy(1, 5));
    		return builder.getPanel();
    	}
     
    	private void initComponents() {
    		libelleClientOrigineField = new JTextField();
    		libelleClientDestinataireField = new JTextField();
    		codeUicOrigineField = new JTextField();
    		codeUicOrigineField.addActionListener(searchOrigineAction);
    		codeUicDestinationField = new JTextField();
    		codeUicDestinationField.addActionListener(searchDestinationAction);
    		codeGareOrigineField = new JTextField();
    		codeGareOrigineField.addActionListener(searchOrigineAction);
    		codeGareDestinationField = new JTextField();
    		codeGareDestinationField.addActionListener(searchDestinationAction);
    		codeLieuOrigineField = new JTextField();
    		codeLieuOrigineField.addActionListener(searchOrigineAction);
    		codeLieuDestinationField = new JTextField();
    		codeLieuDestinationField.addActionListener(searchDestinationAction);
    		libelleOrigineField = new JTextField();
    		libelleOrigineField.setEditable(false);
    		libelleDestinationField = new JTextField();
    		libelleDestinationField.setEditable(false);
    		debutPeriodeOperationnelleField = SwingComponentFactory
    				.createDateField(false, false);
    		finPeriodeOperationnelleField = SwingComponentFactory.createDateField(
    				false, false);
    		debutPeriodeStatistiqueField = SwingComponentFactory.createDateField(
    				false, false);
    		finPeriodeStatistiqueField = SwingComponentFactory.createDateField(
    				false, false);
    		model = new SpinnerNumberModel(1, 1,
    				1000, 1); 
    		nombreASelectionnerField = new JSpinner(model);
            nombreASelectionnerField.addChangeListener(this);
    		removeOrigineLabel = new JRemoveLabel();
    		removeOrigineLabel.addActionListener(new RemoveOrigineActionListener());
    		removeDestinationLabel = new JRemoveLabel();
    		removeDestinationLabel
    				.addActionListener(new RemoveDestinationActionListener());
     
    	}
     
    	private void initComponentsAnnotations() {
     
    	}
     
    	private void initEventHandling() {
     
    	}
     
    	private JPanel buildInfoAreaPane() {
    		infoLabel = new JLabel(ValidationResultViewFactory.getInfoIcon());
    		infoArea = new JTextArea(1, 38);
    		infoArea.setEditable(false);
    		infoArea.setOpaque(false);
    		FormLayout layout = new FormLayout("pref, 2dlu, default", "pref");
    		PanelBuilder builder = new PanelBuilder(layout);
    		CellConstraints cc = new CellConstraints();
    		builder.add(infoLabel, cc.xy(1, 1));
    		builder.add(infoArea, cc.xy(3, 1));
    		infoAreaPane = builder.getPanel();
    		infoAreaPane.setVisible(false);
    		return infoAreaPane;
    	}
     
    	/**
             * affichage des components
             * 
             * @return JComponent
             */
     
    	private JComponent buildEditorPanel() {
     
    		FormLayout layout = new FormLayout(
    				"RIGHT:MAX(40DLU;PREF):NONE,FILL:4DLU:NONE,FILL:21DLU:NONE,FILL:4DLU:NONE,FILL:50DLU:NONE,FILL:4DLU:NONE,FILL:50DLU:NONE,FILL:3DLU:NONE,RIGHT:MAX(40DLU;PREF):NONE,FILL:4DLU:NONE,FILL:21DLU:NONE,FILL:4DLU:NONE,FILL:20DLU:NONE,FILL:4DLU:NONE,FILL:26DLU:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0)",
    				"CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,FILL:DEFAULT:NONE");
    		PanelBuilder builder = new PanelBuilder(layout);
    		CellConstraints cc = new CellConstraints();
    		builder.add(libelleClientOrigineField, cc.xyw(3, 1, 3));
    		builder.addLabel("Libelle client origine", cc.xy(1, 1));
    		builder.addLabel("Lieu origine", cc.xy(1, 3));
    		builder.addLabel("Lieu destination", cc.xy(1, 5));
    		builder.addLabel("Début période statistique", cc.xy(1, 7));
    		builder.add(codeUicOrigineField, cc.xy(3, 3));
    		builder.add(codeUicDestinationField, cc.xy(3, 5));
    		builder.add(codeGareOrigineField, cc.xy(5, 3));
    		builder.add(codeGareDestinationField, cc.xy(5, 5));
    		builder.add(codeLieuOrigineField, cc.xy(7, 3));
    		builder.add(codeLieuDestinationField, cc.xy(7, 5));
    		builder.add(libelleOrigineField, cc.xyw(9, 3, 3));
    		builder.add(libelleDestinationField, cc.xyw(9, 5, 3));
    		builder.add(new JButton(searchOrigineAction), cc.xy(13, 3));
    		builder.add(new JButton(searchDestinationAction), cc.xy(13, 5));
    		builder.addLabel("Libelle client destinataire", cc.xywh(7, 1, 3, 1,
    				CellConstraints.RIGHT, CellConstraints.DEFAULT));
    		builder.add(libelleClientDestinataireField, cc.xyw(11, 1, 5));
    		builder.addLabel("Fin  période statistique", cc.xywh(7, 7, 3, 1,
    				CellConstraints.RIGHT, CellConstraints.DEFAULT));
    		builder.add(debutPeriodeStatistiqueField, cc.xyw(3, 7, 3));
    		builder.add(finPeriodeStatistiqueField, cc.xywh(11, 7, 5, 1));
    		builder.add(debutPeriodeOperationnelleField, cc.xywh(3, 9, 3, 1));
    		builder.add(removeOrigineLabel, cc.xy(15, 3));
    		builder.add(removeDestinationLabel, cc.xy(15, 5));
    		builder.addLabel("Nombre à séléctionner*", cc.xy(1, 11));
    		builder.addLabel("Début période opérationnelle", cc.xy(1, 9));
    		builder.addLabel("Fin  période opérationnelle", cc.xywh(7, 9, 3, 1,
    				CellConstraints.RIGHT, CellConstraints.DEFAULT));
    		builder.add(finPeriodeOperationnelleField, cc.xywh(11, 9, 5, 1));
    		builder.add(nombreASelectionnerField, cc.xywh(3, 11, 3, 1));
     
    		return builder.getPanel();
    	}
     
    	public int showDialog() {
    		return showDialog(null, null, null, null, null, null, 0);
    	}
     
    	public int showDialog(ILieu origine, ILieu destination,
    			String clientOrigine, String clientDestinataire, Date debutPeriode,
    			Date finPeriode, int nombreAPiocher) {
     
    		if (origine != null) {
    			setOrigine(origine);
    		} else {
    			removeOrigine();
    		}
    		if (destination != null) {
    			setDestination(destination);
    		} else {
    			removeDestination();
    		}
     
    		if (debutPeriode != null) {
     
    			debutPeriodeOperationnelleField.setValue(debutPeriode.getTime());
     
    		} else {
     
    			debutPeriodeOperationnelleField.setValue(null);
    		}
    		if (finPeriode != null) {
    			finPeriodeOperationnelleField.setValue(finPeriode.getTime());
    		} else {
    			finPeriodeOperationnelleField.setValue(null);
    		}
    		if (clientOrigine != null) {
    			libelleClientOrigineField.setText(clientOrigine);
    		} else {
    			libelleClientOrigineField.setText(null);
    		}
    		if (clientDestinataire != null) {
    			libelleClientDestinataireField.setText(clientDestinataire);
    		} else {
    			libelleClientDestinataireField.setText(null);
    		}
    		nombreASelectionnerField.setValue(nombreAPiocher);
     
    		dialog = new JDialogModel(TEXT_ADD_TITLE, TEXT_ADD_SUBTITLE, this,
    				new Action[] { acceptAction, cancelAction }, cancelAction);
    		dialog.setResizable(true);
    		dialog.showDialog();
    		dialog.dispose();
    		return returnValue;
    	}
     
    	public ILieu getSelectedLieuOrigine() {
    		return origine;
    	}
     
    	public ILieu getSelectedLieuDestination() {
    		return destination;
    	}
     
    	private void setOrigine(ILieu lieu) {
    		origine = lieu;
    		codeUicOrigineField.setText(lieu.getCodeUic());
    		codeGareOrigineField.setText(lieu.getCodeGare());
    		codeLieuOrigineField.setText(lieu.getCodeLieu());
    		libelleOrigineField.setText(lieu.getLibelle());
    		updateOrigine();
    	}
     
    	private void updateOrigine() {
    		if (libelleOrigineField.getText().equals("")) {
    			removeOrigineLabel.showErrorIcon(TEXT_GARE_ERROR_TOOLTIPS);
    		} else {
    			removeOrigineLabel.showValidateIcon(TEXT_GARE_VALIDATE_TOOLTIPS);
    		}
    	}
     
    	private void removeOrigine() {
    		origine = null;
    		codeUicOrigineField.setText(null);
    		codeGareOrigineField.setText(null);
    		codeLieuOrigineField.setText(null);
    		libelleOrigineField.setText(null);
    		updateOrigine();
    	}
     
    	private void setDestination(ILieu lieu) {
    		destination = lieu;
    		codeUicDestinationField.setText(lieu.getCodeUic());
    		codeGareDestinationField.setText(lieu.getCodeGare());
    		codeLieuDestinationField.setText(lieu.getCodeLieu());
    		libelleDestinationField.setText(lieu.getLibelle());
    		updateDestination();
    	}
     
    	private void updateDestination() {
    		if (libelleDestinationField.getText().equals("")) {
    			removeDestinationLabel.showErrorIcon(TEXT_GARE_ERROR_TOOLTIPS);
    		} else {
    			removeDestinationLabel
    					.showValidateIcon(TEXT_GARE_VALIDATE_TOOLTIPS);
    		}
    	}
     
    	private void removeDestination() {
    		destination = null;
    		codeUicDestinationField.setText(null);
    		codeGareDestinationField.setText(null);
    		codeLieuDestinationField.setText(null);
    		libelleDestinationField.setText(null);
    		updateDestination();
    	}
     
    	private final class AcceptAction extends AbstractAcceptAction {
    		private static final long serialVersionUID = 1L;
     
    		public void actionPerformed(ActionEvent e) {
    			returnValue = ACCEPT_OPTION;
    			dialog.closeDialog();
    		}
    	}
     
    	private final class CancelAction extends AbstractCancelAction {
    		private static final long serialVersionUID = 1L;
     
    		public void actionPerformed(ActionEvent e) {
    			returnValue = CANCEL_OPTION;
    			dialog.closeDialog();
    		}
    	}
     
    	private final class SearchOrigineAction extends AbstractSearchAction {
    		private static final long serialVersionUID = 4737192950769837825L;
     
    		public void actionPerformed(ActionEvent e) {
    			boolean search = !codeUicOrigineField.getText().equals("")
    					|| !codeGareOrigineField.getText().equals("")
    					|| !codeLieuOrigineField.getText().equals("");
    			SearchLieuDialog dialog = new SearchLieuDialog();
    			if (dialog.showDialog(codeUicOrigineField.getText(),
    					codeGareOrigineField.getText(), codeLieuOrigineField
    							.getText(), search) == SearchLieuDialog.ACCEPT_OPTION) {
    				setOrigine(dialog.getSelectedLieu());
    			}
    		}
    	}
     
    	private final class SearchDestinationAction extends AbstractSearchAction {
    		private static final long serialVersionUID = -8357761103552614035L;
     
    		public void actionPerformed(ActionEvent e) {
    			boolean search = !codeUicDestinationField.getText().equals("")
    					|| !codeGareDestinationField.getText().equals("")
    					|| !codeLieuDestinationField.getText().equals("");
    			SearchLieuDialog dialog = new SearchLieuDialog();
    			if (dialog.showDialog(codeUicDestinationField.getText(),
    					codeGareDestinationField.getText(),
    					codeLieuDestinationField.getText(), search) == SearchLieuDialog.ACCEPT_OPTION) {
    				setDestination(dialog.getSelectedLieu());
    			}
    		}
    	}
     
    	private final class RemoveOrigineActionListener implements ActionListener {
    		public void actionPerformed(ActionEvent e) {
    			removeOrigine();
    		}
    	}
     
    	private final class RemoveDestinationActionListener implements
    			ActionListener {
    		public void actionPerformed(ActionEvent e) {
    			removeDestination();
    		}
    	}
     
    	// @SuppressWarnings("unused")
    	// private final class ValidationNombreAPiocherActionListener implements
    	// ActionListener {
    	//	
    	// public void actionPerformed(ActionEvent e) {
    	//	
    	// AddEditStatistiquesCriteresAjoutVoyageDialog dialog = new
    	// AddEditStatistiquesCriteresAjoutVoyageDialog();
    	//	
    	// if (dialog.getNombreAPiocher() > 1000)
    	// nombreASelectionnerField.setValue(1000);
    	// }
    	// }
     
    	public int getNombreAPiocher() {
    		return (Integer) nombreASelectionnerField.getValue();
    	}
     
    	public String getLibelleClientOrigine() {
    		return libelleClientOrigineField.getText();
    	}
     
    	public String getLibelleClientDestination() {
    		return libelleClientDestinataireField.getText();
    	}
     
    	public Date getDebutPeriode() {
     
    		Date toDate = (Date) debutPeriodeStatistiqueField.getValue();
    		return toDate;
    	}
     
    	public Date getFinPeriode() {
     
    		Date toDate = (Date) finPeriodeStatistiqueField.getValue();
    		return toDate;
    	}
     
    	public void stateChanged(ChangeEvent ce) {
    		int valeur =model.getNumber().intValue();
    		if (valeur > 1000){
    			nombreASelectionnerField.setValue(1000);
    		System.out
    				.println("Attention: vous ne pouvez pas dépasser 1000 ajout ");
    	}
    		else{
     
    		}
    	}
     
    //
    //	public SpinnerModel getModel() {
    //		return model;
    //	}
    //
    //	private final class MySpinner implements SpinnerModel {
    //
    //		public void addChangeListener(ChangeListener l) {
    //			ChangeEvent ce;
    //			l.stateChanged();
    //
    //		}
    //
    //		public Object getNextValue() {
    //			return null;
    //		}
    //
    //		public Object getPreviousValue() {
    //			return null;
    //		}
    //
    //		public Object getValue() {
    //
    //			return nombreASelectionnerField.getValue();
    //		}
    //
    //		public void removeChangeListener(ChangeListener l) {
    //
    //		}
    //
    //		public void setValue(Object value) {
    //			nombreASelectionnerField.setValue(value);
    //
    //		}
    //
    //	}

    J'espère que je me suis bien fait comprendre cette fois ci .

    Merci d'avance

    Cdt,

  13. #13
    Membre confirmé
    Inscrit en
    Août 2004
    Messages
    86
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 86
    Par défaut message d'erreur
    SVP, j'aimerais bien aussi afficher un message d'erreur à l'utilisateur lorsqu'il donne un nb>1000 en ajustant le nb à 1000.

    merci d'avance

  14. #14
    Membre émérite Avatar de jojodu31
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    875
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2008
    Messages : 875
    Par défaut
    dit moi ... juste pour être sûr... dans ton spinner tu n'écris pas au clavier, tu utilise seulement les flèches n'est ce pas ?

  15. #15
    Membre confirmé
    Inscrit en
    Août 2004
    Messages
    86
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 86
    Par défaut
    je saisie au clavier car si j'utilise seulement les flèches,pour atteindre 1000 c'est pas rapide!!

  16. #16
    Membre émérite Avatar de jojodu31
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    875
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2008
    Messages : 875
    Par défaut
    aaaaaaaHHHHHHHHHH c'est pour ça !!!
    le model ne controle pas les saisies au clavier ! c'est juste pour l'appui sur les flèches....
    tape 999 au clavier et continu avec les flèches tu verra que ça marche bien
    et si 1000 est long à atteindre c'est qu'un spinner n'est pas la meilleure solution ... (voir JSlider)

  17. #17
    Membre Expert
    Avatar de natha
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 346
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 346
    Par défaut
    Citation Envoyé par coquero Voir le message
    tjs le même pb,quand l'utilisateur donne un nb<=1000 ça passe bien tandis que si nb>1000 ça fait rien,je voulais ajouter l'option que si le nb>1000 le nb redevient 1000
    Je m'excuse mais si on saisie 1010, le chiffre revient à 1000 une fois le focus perdu. Il n'y a aucun problème sur ce comportement, il peut facilement être vérifié avec le programme de test que j'ai fourni ci-dessus.

    C'est un non-problème cette discussion...

    Citation Envoyé par jojodu31
    le model ne controle pas les saisies au clavier ! c'est juste pour l'appui sur les flèches....
    Depuis quand ???

  18. #18
    Membre émérite Avatar de jojodu31
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    875
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2008
    Messages : 875
    Par défaut
    une fois le focus perdu.
    voilà je parlais d'un contrôle en direct

  19. #19
    Membre Expert
    Avatar de natha
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 346
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 346
    Par défaut
    Citation Envoyé par jojodu31 Voir le message
    voilà je parlais d'un contrôle en direct
    Dans ce cas ton listener ne marchera pas de toute façon car il faut perdre le focus ou utiliser les flèches pour déclencher l'événement adéquat.

    Si on veut contrôler à la saisie il faut modifier l'editor du JSpinner et passer par un DocumentListener sur cet editor (de type JFormattedTextField par exemple).

  20. #20
    Membre émérite Avatar de jojodu31
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    875
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2008
    Messages : 875
    Par défaut
    je sais oui ... j'ai pas de problèmes moi là (pour une fois )
    c'était juste pour signaler que l'on pouvait entrer n'importe quelle valeur au clavier ( jusqu'à la perte de focus...)

Discussions similaires

  1. Nombre maximal de destinataire dans outlook 2007
    Par sofien dans le forum Outlook
    Réponses: 2
    Dernier message: 07/12/2007, 08h15
  2. Quel est le nombre maximal de tables dans un DataSet ?
    Par Philorix dans le forum Accès aux données
    Réponses: 6
    Dernier message: 11/09/2006, 14h18
  3. Nombre maximal de fichiers dans un répertoire
    Par cquilgars dans le forum Administration système
    Réponses: 10
    Dernier message: 15/12/2005, 12h04
  4. [C#]saisir que un nombre decimal dans 1 textBox
    Par mcay dans le forum Windows Forms
    Réponses: 25
    Dernier message: 04/11/2005, 15h43
  5. Réponses: 7
    Dernier message: 16/11/2004, 15h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo