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 :

Problème de GridBagLayout


Sujet :

AWT/Swing Java

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre émérite
    Avatar de Gouyon
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    1 137
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 137
    Billets dans le blog
    5
    Par défaut Problème de GridBagLayout
    Salut à tous

    Je commence à m'arracher les cheveux avec un GridBagLayout
    Voilà le problème:
    Dans un JPanel j'affiche 2 lignes de led avec un label comme ceci

    Le problème c'est que j'ai un gros trou à la seconde ligne entre la première led et les autres.
    J'ai fouillé un peu partout dans les tutoriels et les exemples de codes et vu ce que j'ai programmé (cf code si dessous) je devrais avoir ceci


    Voici le code

    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
     
        public void Design2() {
     
    	setLayout(new GridBagLayout());
    	setBorder(BorderFactory.createRaisedBevelBorder());
     
    	for (int indx = 0; indx < lbl.length; indx++) {
     
    	    // Led les alarmes
     
    	    m_LedAlarme[indx] = new Led();
    	    m_LedAlarme[indx].setLedColor(LedColor.RED);
     
    	    org.jdesktop.layout.GroupLayout ledLayout = new org.jdesktop.layout.GroupLayout(
    		    m_LedAlarme[indx]);
    	    ledLayout.setHorizontalGroup(ledLayout.createParallelGroup(
    		    org.jdesktop.layout.GroupLayout.LEADING).add(0, 48,
    		    Short.MAX_VALUE));
    	    ledLayout.setVerticalGroup(ledLayout.createParallelGroup(
    		    org.jdesktop.layout.GroupLayout.LEADING).add(0, 48,
    		    Short.MAX_VALUE));
    	    m_LedAlarme[indx].setLayout(ledLayout);
    	    m_LedAlarme[indx].setMinimumSize(new Dimension(48, 48));
     
    	    GridBagConstraints gbcS = new GridBagConstraints();
    	    gbcS.gridx = 2 * indx;
    	    gbcS.gridy = 1;
    	    gbcS.gridwidth = 1;
    	    gbcS.gridheight = 1;
    	    gbcS.anchor = GridBagConstraints.LINE_END;
    	    gbcS.fill = GridBagConstraints.NONE;
    	    gbcS.insets = new Insets(5, 5, 5, 5);
    	    gbcS.weightx = 0.0;
    	    gbcS.weighty = 0.0;
    	    add(m_LedAlarme[indx], gbcS);
     
    	    // Label contenant le nom du server
    	    m_Label[indx] = new JLabel(lbl[indx]);
    	    GridBagConstraints gbcL = new GridBagConstraints();
    	    gbcL.gridx = 2 * indx + 1;
    	    gbcL.gridy = 1;
    	    gbcL.gridwidth = 1;
    	    gbcL.gridheight = 1;
    	    gbcL.anchor = GridBagConstraints.LINE_START;
    	    gbcL.fill = GridBagConstraints.NONE;
    	    gbcL.insets = new Insets(5, 5, 5, 5);
    	    gbcL.weightx = 0.0;
    	    gbcL.weighty = 0.0;
    	    add(m_Label[indx], gbcL);
    	}
     
    	GridBagConstraints gbcLt = new GridBagConstraints();
    	gbcLt.gridx = 2 * lbl.length + 1;
    	gbcLt.gridy = 1;
    	gbcLt.gridwidth = 1;
    	gbcLt.gridheight = 1;
    	gbcLt.anchor = GridBagConstraints.CENTER;
    	gbcLt.fill = GridBagConstraints.NONE;
    	gbcLt.insets = new Insets(5, 5, 5, 5);
    	gbcLt.weightx = 1.0;
    	gbcLt.weighty = 0.0;
    	add(new JLabel(""), gbcLt);
     
    	JLabel Titre = new JLabel("Stabilisation");
    	GridBagConstraints gbcT = new GridBagConstraints();
    	gbcT.gridx = 1;
    	gbcT.gridy = 0;
    	gbcT.gridwidth = 1;
    	gbcT.gridheight = 1;
    	gbcT.anchor = GridBagConstraints.LINE_END;
    	gbcT.fill = GridBagConstraints.NONE;
    	gbcT.insets = new Insets(5, 5, 5, 5);
    	gbcT.weightx = 0.0;
    	gbcT.weighty = 0.0;
    	add(Titre, gbcT);
     
    	m_LedStabON = new Led();
    	m_LedStabON.setLedColor(LedColor.GREEN);
    	org.jdesktop.layout.GroupLayout ledLayout = new org.jdesktop.layout.GroupLayout(
    		m_LedStabON);
    	ledLayout.setHorizontalGroup(ledLayout.createParallelGroup(
    		org.jdesktop.layout.GroupLayout.LEADING).add(0, 48,
    		Short.MAX_VALUE));
    	ledLayout.setVerticalGroup(ledLayout.createParallelGroup(
    		org.jdesktop.layout.GroupLayout.LEADING).add(0, 48,
    		Short.MAX_VALUE));
    	m_LedStabON.setLayout(ledLayout);
    	m_LedStabON.setMinimumSize(new Dimension(48, 48));
    	GridBagConstraints gbcS = new GridBagConstraints();
    	gbcS.gridx = 2;
    	gbcS.gridy = 0;
    	gbcS.gridwidth = 1;
    	gbcS.gridheight = 1;
    	gbcS.anchor = GridBagConstraints.LINE_START;
    	gbcS.fill = GridBagConstraints.NONE;
    	gbcS.insets = new Insets(5, 5, 5, 5);
    	gbcS.weightx = 1.0;
    	gbcS.weighty = 0.0;
    	add(m_LedStabON, gbcS);
     
        }
    Si quelqu'un a une idée
    Images attachées Images attachées   

Discussions similaires

  1. 2 problèmes : Thread & GridBagLayout
    Par M4veR1K dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 01/07/2009, 09h13
  2. Problème avec GridBagLayout
    Par alexis0587 dans le forum Agents de placement/Fenêtres
    Réponses: 6
    Dernier message: 25/03/2009, 22h57
  3. problème de GridBagLayout
    Par Invité1 dans le forum Agents de placement/Fenêtres
    Réponses: 5
    Dernier message: 19/02/2008, 17h13
  4. Problème de GridBagLayout (disposition jscrollbar)
    Par akiri dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 17/11/2007, 11h02
  5. Problème avec GridBagLayout dans JPanel
    Par caneman dans le forum AWT/Swing
    Réponses: 4
    Dernier message: 19/12/2006, 22h32

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