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 :

Layout et pas d'espacement entre label


Sujet :

AWT/Swing Java

  1. #1
    Membre éprouvé
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 715
    Détails du profil
    Informations personnelles :
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 715
    Par défaut Layout et pas d'espacement entre label
    Bonsoir

    j'utilise un VerticalLayout qui hérite de FlowLayout, mais lorsque j'insere mes Label je n'arrive pas à enlever les espaces.
    Il faudrait que mes deux libéllés se touchent, ou alors pouvoir mette un cr dans ma chaine pour avoir le libélle sur deux lignes.

    Merci d'avance
    Philippe

  2. #2
    Membre Expert
    Avatar de gifffftane
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 354
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire (Rhône Alpes)

    Informations forums :
    Inscription : Février 2007
    Messages : 2 354
    Par défaut
    Le VerticalLayout n'est pas un composant du JDK, à ma connaissance, aussi il est difficile de t'aider, sauf par ceux qui connaissent ce composant.

    Si ce choix peut être remis en cause, intéresse-toi au BoxLayout, plus populaire, et avec lequel tu devrais pouvoir arriver à coller les labels.

  3. #3
    Membre éprouvé
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 715
    Détails du profil
    Informations personnelles :
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 715
    Par défaut
    bonjour

    je me suis mal exprime, c'est le texte à l'interieur des labels que je souhaite coller l'un à l'autre sur le plan vertical .
    J'ai actuellement de libelle l'un en dessous de l'autre et j'ai trop d'espace entre mes deux textes. Le verticalLayout hérite de FlowLayout .


    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
    package util.applet;
     
    import java.awt.*;
    import java.io.Serializable;
     
    public class VerticalFlowLayout extends FlowLayout
        implements Serializable
    {
     
        public VerticalFlowLayout()
        {
            this(0, 5, 5, true, false);
        }
     
        public VerticalFlowLayout(boolean hfill, boolean vfill)
        {
            this(0, 5, 5, hfill, vfill);
        }
     
        public VerticalFlowLayout(int align)
        {
            this(align, 5, 5, true, false);
        }
     
        public VerticalFlowLayout(int align, boolean hfill, boolean vfill)
        {
            this(align, 5, 5, hfill, vfill);
        }
     
        public VerticalFlowLayout(int align, int hgap, int vgap, boolean hfill, boolean vfill)
        {
            setAlignment(align);
            this.hgap = hgap;
            this.vgap = vgap;
            this.hfill = hfill;
            this.vfill = vfill;
        }
     
        public Dimension preferredLayoutSize(Container target)
        {
            Dimension tarsiz = new Dimension(0, 0);
            for(int i = 0; i < target.getComponentCount(); i++)
            {
                Component m = target.getComponent(i);
                if(m.isVisible())
                {
                    Dimension d = m.getPreferredSize();
                    tarsiz.width = Math.max(tarsiz.width, d.width);
                    if(i > 0)
                        tarsiz.height += hgap;
                    tarsiz.height += d.height;
                }
            }
     
            Insets insets = target.getInsets();
            tarsiz.width += insets.left + insets.right + hgap * 2;
            tarsiz.height += insets.top + insets.bottom + vgap * 2;
            return tarsiz;
        }
     
        public Dimension minimumLayoutSize(Container target)
        {
            Dimension tarsiz = new Dimension(0, 0);
            for(int i = 0; i < target.getComponentCount(); i++)
            {
                Component m = target.getComponent(i);
                if(m.isVisible())
                {
                    Dimension d = m.getMinimumSize();
                    tarsiz.width = Math.max(tarsiz.width, d.width);
                    if(i > 0)
                        tarsiz.height += vgap;
                    tarsiz.height += d.height;
                }
            }
     
            Insets insets = target.getInsets();
            tarsiz.width += insets.left + insets.right + hgap * 2;
            tarsiz.height += insets.top + insets.bottom + vgap * 2;
            return tarsiz;
        }
     
        public void setVerticalFill(boolean vfill)
        {
            this.vfill = vfill;
        }
     
        public boolean getVerticalFill()
        {
            return vfill;
        }
     
        public void setHorizontalFill(boolean hfill)
        {
            this.hfill = hfill;
        }
     
        public boolean getHorizontalFill()
        {
            return hfill;
        }
     
        private void placethem(Container target, int x, int y, int width, int height, int first, int last)
        {
            int align = getAlignment();
            if(align == 1)
                y += height / 2;
            if(align == 2)
                y += height;
            for(int i = first; i < last; i++)
            {
                Component m = target.getComponent(i);
                Dimension md = m.getSize();
                if(m.isVisible())
                {
                    int px = x + (width - md.width) / 2;
                    m.setLocation(px, y);
                    y += vgap + md.height;
                }
            }
     
        }
     
        public void layoutContainer(Container target)
        {
            Insets insets = target.getInsets();
            int maxheight = target.getSize().height - (insets.top + insets.bottom + vgap * 2);
            int maxwidth = target.getSize().width - (insets.left + insets.right + hgap * 2);
            int numcomp = target.getComponentCount();
            int x = insets.left + hgap;
            int y = 0;
            int colw = 0;
            int start = 0;
            for(int i = 0; i < numcomp; i++)
            {
                Component m = target.getComponent(i);
                if(m.isVisible())
                {
                    Dimension d = m.getPreferredSize();
                    if(vfill && i == numcomp - 1)
                        d.height = Math.max(maxheight - y, m.getPreferredSize().height);
                    if(hfill)
                    {
                        m.setSize(maxwidth, d.height);
                        d.width = maxwidth;
                    } else
                    {
                        m.setSize(d.width, d.height);
                    }
                    if(y + d.height > maxheight)
                    {
                        placethem(target, x, insets.top + vgap, colw, maxheight - y, start, i);
                        y = d.height;
                        x += hgap + colw;
                        colw = d.width;
                        start = i;
                    } else
                    {
                        if(y > 0)
                            y += vgap;
                        y += d.height;
                        colw = Math.max(colw, d.width);
                    }
                }
            }
     
            placethem(target, x, insets.top + vgap, colw, maxheight - y, start, numcomp);
        }
     
        public static final int TOP = 0;
        public static final int MIDDLE = 1;
        public static final int BOTTOM = 2;
        int hgap;
        int vgap;
        boolean hfill;
        boolean vfill;
    }

Discussions similaires

  1. [XSL-FO] Pas d'espace entre plusieurs images
    Par boudincweole10 dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 05/12/2008, 12h18
  2. Réponses: 5
    Dernier message: 25/06/2008, 15h06
  3. ne veut pas d'espaces entre les images dans une cellule
    Par cortex024 dans le forum Mise en page CSS
    Réponses: 6
    Dernier message: 07/12/2006, 15h30
  4. [Struts-Layout] espace entre colonne
    Par david06600 dans le forum Struts 1
    Réponses: 1
    Dernier message: 09/10/2006, 18h36
  5. [img] Pas d'espace entre les images
    Par Mister Nono dans le forum Balisage (X)HTML et validation W3C
    Réponses: 12
    Dernier message: 09/05/2006, 17h04

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