Bonjour,
j"ai un problème avec mon interface graphique en java.
Je souhaite créer un Jlabel qui contiendrait une valeur par défaut. Cette valeur peur être modifiée grace à un bouton ouvrant une InputDialog. En affichant le résultat dans la console, j'arrive bien a changé la variable mais le panel ne se change pas. Pourtant j'effectue bien un repaint.

Voici un apercu de mon code. Merci

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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class GUI extends JFrame{
 
  public static JPanel Info;
  public static JTextField boitePosition; // Zone de texte de la position
  public static JButton BouttonIRmin;
 
  public static int IRmin;
 
 
  // Listener du boutton
  public static class B1Listener implements ActionListener {
    public void actionPerformed(ActionEvent e)  {
      // ouverture de la fenetre de Dialogue
      System.out.println("avant je passe "+GUI.IRmin);
      int tailleIR=0;
      try {
        tailleIR=Integer.parseInt(JOptionPane.showInputDialog(null,"Taille IR min :","",JOptionPane.QUESTION_MESSAGE));
      }
      catch(java.lang.NumberFormatException ex) {
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(null,"Veuillez entrer un nombre valide","Erreur de l'application",JOptionPane.ERROR_MESSAGE);
        System.exit(-1);
      } 
      GUI.IRmin=tailleIR; // changement de la variable
      System.out.println("apres je passe "+GUI.IRmin);
      GUI.Info.repaint(); // repaint
    }
  }
 
  // Classe panel
  public class JPanelInfo extends JPanel{
    public JPanelInfo(){
      JLabel l=new JLabel("IR min "+IRmin);
      l.setBounds(10,20,100,17);
      this.add(l);
    }
  }
 
  public GUI(){
    // Parametre de la frame
    this.setTitle("Detection des small RNA");
    this.setSize(600,400);
    this.setLocation(100,50);
    this.setLayout(null);
 
    // création de la frame
    this.Info = new JPanelInfo();
    this.Info.setBounds(0,0,80,100);
    this.getContentPane().add(Info);
 
    // Ajout du boutton
    this.BouttonIRmin = new JButton(" Modifier ");
    this.BouttonIRmin.setBounds(200,5,100,25);
    this.BouttonIRmin.addActionListener(new B1Listener());
    this.getContentPane().add(this.BouttonIRmin);
 
    /*
    JLabel l=new JLabel("IR min bis "+this.IRmin);
    l.setBounds(200,200,100,17);
    this.add(l);
    */
 
    this.setVisible(true);
  }
}
Configuration: Linux Fedora 5
Jdk 1.5