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

Agents de placement/Fenêtres Java Discussion :

GridBagLayout + Position de bouton


Sujet :

Agents de placement/Fenêtres Java

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    176
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 176
    Par défaut GridBagLayout + Position de bouton
    Bonjour,

    Je commence a perdre mon latin avec les GridBagLayout.

    Quelqu'un peut m'éclairer sur le sujet. J'aimerai faire en sorte que mon bouton nouveau soit d'une taille normale. Je sais qu'il prend cette taille à cause de la taille de la ligne par rapport à la JTable mais je ne sais plus comment faire.

    Merci de votre aide.



    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
    package be.roose.vue;
     
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JInternalFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
     
    public class DesktopContactListe extends JInternalFrame implements ActionListener{
     
        private JPanel monPanel = new JPanel();
        private GridBagConstraints gbc = new GridBagConstraints();
        private JScrollPane maScrollPaneContact;
        private JScrollPane maScrollPanePatient;
        private JTable maTableContact;
        private JTable maTablePatient;
        private JLabel nomTablePatient = new JLabel("Les patients");
        private JLabel nomTableContact = new JLabel("Contacts du patient");
        private JLabel prenomContactLabel = new JLabel("Prénom");
        private JLabel nomContactLabel = new JLabel("Nom");
        private JLabel mailContactLabel = new JLabel("E-Mail");
        private JLabel telContactLabel = new JLabel("Téléphone");
        private JLabel gsmContactLabel = new JLabel("GSM");
        private JLabel actifContactLabel = new JLabel("Actif");
        private JTextField prenomContactField = new JTextField();
        private JTextField nomContactField = new JTextField();    
        private JTextField mailContactField = new JTextField("");
        private JTextField telContactField = new JTextField("");
        private JTextField gsmContactField = new JTextField("");    
        private JComboBox actifContactCombo = new JComboBox();
        private JButton quitterBouton = new JButton("Quitter");
        private JButton rafraichirBouton = new JButton("Rafraichir");
        private JButton sauverBouton = new JButton("Sauver");
        private JButton nouveauBouton = new JButton("Nouveau");
        private JButton supprimerBouton = new JButton("Supprimer");
     
        public DesktopContactListe(){
            this.setTitle("Liste des Contacts");
            this.setClosable(true);
            this.setResizable(true);
            this.setSize(790, 500);
            this.setVisible(true);
            System.out.println("Contact!");
            // Test JTable
     
            Object[][] data = {    {"Test1", "28 ans", "1.80 cm"},
                    {"Test2", "28 ans", "1.80 cm"},
                    {"Test3", "24 ans", "1.90 cm"},
                    {"Test4", "32 ans", "1.85 cm"}
            };
            String  title[] = {"Pseudo", "Age", "Taille"};
            this.maTableContact = new JTable(data, title);
            this.maTablePatient = new JTable (data,title);
            maScrollPaneContact = new JScrollPane(maTableContact);
            maScrollPanePatient = new JScrollPane(maTablePatient);
     
            // On défnit la combo
            actifContactCombo.addItem("Oui");
            actifContactCombo.addItem("Non");
     
            // On définit le Grid
     
            monPanel.setLayout(new GridBagLayout());
     
            // On place les Label
     
            gbc.fill = GridBagConstraints.BOTH;
            gbc.insets = new Insets (10,10,10,10);
     
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.gridwidth = 2;
            monPanel.add(nomTablePatient,gbc);
            gbc.gridx = 0;
            gbc.gridy = 3;
            monPanel.add(nomTableContact,gbc);
     
            gbc.gridx = 0;
            gbc.gridy = 6;
            gbc.gridwidth = 1;
            monPanel.add(prenomContactLabel,gbc);
            gbc.gridx = 0;
            gbc.gridy = 7;
            monPanel.add(nomContactLabel,gbc);
            gbc.gridx = 0;
            gbc.gridy = 8;
            monPanel.add(mailContactLabel,gbc);
            gbc.gridx = 4;
            gbc.gridy = 6;
            monPanel.add(telContactLabel,gbc);
            gbc.gridx = 4;
            gbc.gridy = 7;
            monPanel.add(gsmContactLabel,gbc);
            gbc.gridx = 4;
            gbc.gridy = 8;
            monPanel.add(actifContactLabel,gbc);
     
            // On place les TextField
     
            gbc.gridx = 1;
            gbc.gridy = 6;
            gbc.weightx=50;
            gbc.gridwidth = 1;
            monPanel.add(prenomContactField,gbc);
            gbc.gridx = 1;
            gbc.gridy = 7;
            monPanel.add(nomContactField,gbc);
            gbc.gridx = 1;
            gbc.gridy = 8;
            monPanel.add(mailContactField,gbc);
            gbc.gridx = 5;
            gbc.gridy = 6;
            gbc.gridwidth = 1;
            monPanel.add(telContactField,gbc);
            gbc.gridx = 5;
            gbc.gridy = 7;
            monPanel.add(gsmContactField,gbc);
            gbc.gridx = 5;
            gbc.gridy = 8;
            monPanel.add(actifContactCombo,gbc);
     
            // On place les boutons
            gbc.weightx=0;
            gbc.weighty=0;
            gbc.gridx = 8;
            gbc.gridy = 4;
            gbc.gridwidth = 1;
            monPanel.add(nouveauBouton,gbc);
            gbc.gridx = 8;
            gbc.gridy = 5;
            monPanel.add(supprimerBouton,gbc);
            gbc.gridx = 8;
            gbc.gridy = 6;
            monPanel.add(rafraichirBouton,gbc);
            gbc.gridx = 8;
            gbc.gridy = 7;
            monPanel.add(sauverBouton,gbc);        
            gbc.gridx = 8;
            gbc.gridy = 8;
            monPanel.add(quitterBouton,gbc);
     
            // On place la table Contact
            gbc.gridx = 0;
            gbc.gridy = 1;
            gbc.gridwidth = 8;
            gbc.weightx=100;
            gbc.weighty=100;
            monPanel.add(maScrollPaneContact,gbc);
     
            // On place la table Patient
            gbc.gridx = 0;
            gbc.gridy = 4;
            gbc.gridwidth = 8;
            gbc.weightx=100;
            gbc.weighty=100;
            monPanel.add(maScrollPanePatient,gbc);
     
     
            // On attache monPanel
            this.getContentPane().add(monPanel);
     
            // Ecouteur
     
            quitterBouton.addActionListener(this);
     
        }
     
        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
            // On ferme la JInternalFrame
            this.dispose();
        }
     
    }

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 278
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 278
    Par défaut
    Il faut que tu empêches ton composant de se redimensionner.
    Pour cela, utilise la propriété gbc.fill = GridBagConstraints.NONE; sur ton bouton nouveau. Ainsi il gardera sa taille.

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    176
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 176
    Par défaut
    Effectivement, j'avais complètement loupé ça...

    Merci à toi !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. GridBagLayout, placement de boutons
    Par pendoRa dans le forum Agents de placement/Fenêtres
    Réponses: 14
    Dernier message: 23/03/2010, 14h31
  2. Position des boutons dans un GridView
    Par zooffy dans le forum ASP.NET
    Réponses: 2
    Dernier message: 09/09/2008, 12h16
  3. Position des boutons en gwt-ext
    Par ben.ouadii dans le forum GWT et Vaadin
    Réponses: 4
    Dernier message: 09/06/2008, 15h35
  4. [MFC] Position des boutons dans un ctoolbar
    Par tyarcaouen dans le forum MFC
    Réponses: 1
    Dernier message: 04/12/2007, 09h34

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