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

Interfaces Graphiques en Java Discussion :

Mise en Forme 2


Sujet :

Interfaces Graphiques en Java

  1. #1
    Membre �clair�
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    351
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 351
    Par d�faut Mise en Forme 2
    Bon alors j'ai capt� comment marche le gridBagLayout , et aussi les autres BorderLayout, FlowLayout, les petites Box vertical,Horizontal ect...

    Alors fier de mon apprentissage(grace a nicotine) , j'ai bien a l'ecran mes superbes JPanel disposer a la perfection.

    Mais malheureusement sitot que l'on met quelque chose dans les panels , les panel sont redimentionn�es selon les composants ajout�s et ne garde plus la disposition faite par mon GridBagLayout

    Donc je peux surement imposer des tailles a tous mes composants , avec les setPreferredSize , maximum ect.... Mais alors quel est l'interet de se faire chier a utiliser un GridBagLayout si il faut redimentionner chaque composant mis dans les panels pourqu'il respecte l'affichage ??

  2. #2
    Membre �m�rite
    Avatar de bbclone
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    537
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 537
    Par d�faut
    je croit que t'a pas bien compri le principe du GridBagLayout.

  3. #3
    Membre �clair�
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    351
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 351
    Par d�faut
    pourrais tu etre plus explicite ?

  4. #4
    Membre �m�rite
    Avatar de bbclone
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    537
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 537
    Par d�faut
    tu te souvien de la demo de matisse quand netbeans est sorti?
    j'ai pris quelque minute pour faire la meme chose avec le GridBagLayout

    c'est fais tres vite. ca ressemble mais je viens de remarquer qu'il me manque un truc en haut.
    c'est pas grave.
    c'est juste pour t'expliquer le principe du GridBagLayout.
    regarde cette image:
    http://www.developpez.net/forums/att...1&d=1149959136

    l'objectif faire ca sans diviser en 50 petit panel.
    ca donne ca
    http://www.developpez.net/forums/att...1&d=1149959136

    j'ai pas utiliser la baseline sinon tu aurais eu besoin de java6 ;-)
    Images attach�es Images attach�es   

  5. #5
    Membre �m�rite
    Avatar de bbclone
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    537
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 537
    Par d�faut
    j'ai lu ton autre message sur le GridBagLayout.
    j'ai pas compri comment tu l'utilise
    tu as des array de parametre pour tes GBC?
    ou quelque chose dans le genre?

    ah et pour que vous dite pas que c'est du setLayout(null)
    je met le code

    (fais avec un edi ;-) )

    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
     
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
     
    import javax.swing.*;
     
     
    /**
     * Created by IntelliJ IDEA.
     * User: bebe
     * Date: 10-Jun-2006
     * Time: 18:58:33
     * To change this template use File | Settings | File Templates.
     */
    public class MyPanel extends JPanel {
        private GridBagLayout gridBagLayout1 = new GridBagLayout();
        private JPanel defautIdentityPanel = new JPanel();
        private JLabel titleLabel = new JLabel();
        private GridBagLayout gridBagLayout2 = new GridBagLayout();
        private JLabel yourNameLabel = new JLabel();
        private JLabel emailAddressLabel = new JLabel();
        private JLabel replyToAddressLabel = new JLabel();
        private JLabel organisationLabel = new JLabel();
        private JTextField nameTextField = new JTextField();
        private JTextField emailAddressTextField = new JTextField();
        private JTextField replyAddressTextField = new JTextField();
        private JTextField organisationTextField = new JTextField();
        private JCheckBox attachSignatureCheckBox = new JCheckBox();
        private JTextField signatureTextField = new JTextField();
        private JButton chooseButton = new JButton();
        private JButton editCardButton = new JButton();
        private JCheckBox attachVCardCheckBox = new JCheckBox();
        private JLabel outgoingServerLabel = new JLabel();
        private JComboBox outgoingServerCombobox = new JComboBox();
        private JButton manageIdentitiesButton = new JButton();
        private JScrollPane accountsScrollPane = new JScrollPane();
        private JButton addAccountButton = new JButton();
        private JButton setAsDefaultButton = new JButton();
        private JButton removeAccountButton = new JButton();
        private JButton okButton = new JButton();
        private JButton cancelButton = new JButton();
        private JTree accountTree = new JTree();
     
        public MyPanel() {
            initGui();
        }
     
        private void initGui() {
            this.setLayout(gridBagLayout1);
            this.setSize(new Dimension(626, 474));
            defautIdentityPanel.setBorder(BorderFactory.createTitledBorder("Default Identity"));
            defautIdentityPanel.setLayout(gridBagLayout2);
            titleLabel.setText("Each account has an identity, wich is the information .... ");
            yourNameLabel.setText("Your Name :");
            emailAddressLabel.setText("Email Address :");
            replyToAddressLabel.setText("Reply to address :");
            organisationLabel.setText("Organisation :");
            attachSignatureCheckBox.setText("Attach this signature :");
            attachSignatureCheckBox.setMargin(new Insets(0, 0, 0, 0));
            signatureTextField.setMinimumSize(new Dimension(100, 20));
            signatureTextField.setPreferredSize(new Dimension(300, 20));
            chooseButton.setText("Choose ...");
            editCardButton.setText("Edit Card...");
            attachVCardCheckBox.setText("Attach my VCard to messages");
            outgoingServerLabel.setText("Outgoing Server (SMTP) :");
            manageIdentitiesButton.setText("Manage Identities ...");
            addAccountButton.setText("Add Account...");
            setAsDefaultButton.setText("Set as Default");
            removeAccountButton.setText("Remove Account");
            okButton.setText("OK");
            cancelButton.setText("Cancel");
            defautIdentityPanel.add(titleLabel,
                    new GridBagConstraints(0, 0, GridBagConstraints.REMAINDER,
                            1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
                            new Insets(5, 5, 5, 5),
                            0, 0));
            defautIdentityPanel.add(yourNameLabel,
                    new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                            new Insets(5, 5, 0, 0),
                            0, 0));
            defautIdentityPanel.add(emailAddressLabel,
                    new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                            new Insets(5, 5, 0, 0),
                            0, 0));
            defautIdentityPanel.add(replyToAddressLabel,
                    new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                            new Insets(5, 5, 0, 0),
                            0, 0));
            defautIdentityPanel.add(organisationLabel,
                    new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                            new Insets(5, 5, 0, 0),
                            0, 0));
            defautIdentityPanel.add(nameTextField,
                    new GridBagConstraints(1, 1, GridBagConstraints.REMAINDER,
                            1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                            new Insets(3, 5, 0, 5),
                            0, 0));
            defautIdentityPanel.add(emailAddressTextField,
                    new GridBagConstraints(1, 2, GridBagConstraints.REMAINDER,
                            1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                            new Insets(3, 5, 0, 5),
                            0, 0));
            defautIdentityPanel.add(replyAddressTextField,
                    new GridBagConstraints(1, 3, GridBagConstraints.REMAINDER,
                            1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                            new Insets(3, 5, 0, 5),
                            0, 0));
            defautIdentityPanel.add(organisationTextField,
                    new GridBagConstraints(1, 4, GridBagConstraints.REMAINDER,
                            1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
                            new Insets(3, 5, 0, 5),
                            0, 0));
            defautIdentityPanel.add(attachSignatureCheckBox,
                    new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                            new Insets(10, 5, 0, 0),
                            0, 0));
            defautIdentityPanel.add(signatureTextField,
                    new GridBagConstraints(0, 6, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
                            new Insets(3, 25, 0, 5),
                            0, 0));
            defautIdentityPanel.add(chooseButton,
                    new GridBagConstraints(2, 6, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL,
                            new Insets(3, 0, 0, 5),
                            0, 0));
            defautIdentityPanel.add(editCardButton,
                    new GridBagConstraints(2, 7, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL,
                            new Insets(3, 0, 0, 5),
                            0, 0));
            defautIdentityPanel.add(attachVCardCheckBox,
                    new GridBagConstraints(0, 7, 2, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                            new Insets(5, 5, 0, 0),
                            0, 0));
            defautIdentityPanel.add(outgoingServerLabel,
                    new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                            new Insets(8, 5, 0, 0),
                            0, 0));
            defautIdentityPanel.add(outgoingServerCombobox,
                    new GridBagConstraints(1, 8, GridBagConstraints.REMAINDER,
                            1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                            new Insets(5, 5, 5, 5),
                            0, 0));
            this.add(defautIdentityPanel,
                    new GridBagConstraints(1, 0, 4, 1, 0.6, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                            new Insets(5, 5, 5, 5), 0, 0));
            this.add(manageIdentitiesButton,
                    new GridBagConstraints(3, 1, GridBagConstraints.REMAINDER,
                            1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
                            new Insets(10, 0, 0, 10), 0, 0));
            accountsScrollPane.getViewport().add(accountTree, null);
            this.add(accountsScrollPane,
                    new GridBagConstraints(0, 0, 1, 2, 0.4, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                            new Insets(5, 5, 5, 5), 0, 0));
            this.add(addAccountButton,
                    new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                            new Insets(0, 5, 0, 5), 0, 0));
            this.add(setAsDefaultButton,
                    new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                            new Insets(5, 5, 0, 5), 0, 0));
            this.add(removeAccountButton,
                    new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                            new Insets(5, 5, 0, 5), 0, 2));
            this.add(okButton,
                    new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
                            new Insets(5, 0, 5, 5), 0, 0));
            this.add(cancelButton,
                    new GridBagConstraints(3, 5, 1, 1, 0.1, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
                            new Insets(5, 5, 0, 5), 0, 0));
        }
     
        public static void main(String[] args) {
            JFrame myFrame = new JFrame("GridBagLayout power");
            myFrame.add(new MyPanel());
            myFrame.pack();
            myFrame.setLocationRelativeTo(null);
            myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            myFrame.setVisible(true);
        }
    }

  6. #6
    Membre �clair� Avatar de nicotine002
    Profil pro
    Inscrit en
    D�cembre 2005
    Messages
    577
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : D�cembre 2005
    Messages : 577
    Par d�faut
    En fait c'est une m�thode qui(pour moi en tout cas) me simplifie la vie, tu met toutes les coordonn�es,les poids... dans des tableau, puis tu creer ta boucle correctement afin de bien construire ton GridBag.
    Ca m'a pris m�me pas 5 min pour lui faire son Layout, apr�s c'est une affaire d'avis ou d'habitude

  7. #7
    Membre �m�rite
    Avatar de bbclone
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    537
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 537
    Par d�faut
    je sentait comme si j'avais tricher.
    j'ai corriger pour correspondre en ajoutant les element que j'avait oublier.

    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
     
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.Color;
    import java.awt.Font;
     
    import javax.swing.*;
     
     
    /**
     * Created by IntelliJ IDEA.
     * User: bebe
     * Date: 10-Jun-2006
     * Time: 18:58:33
     * To change this template use File | Settings | File Templates.
     */
    public class MyPanel extends JPanel {
        private GridBagLayout gridBagLayout1 = new GridBagLayout();
        private JPanel defautIdentityPanel = new JPanel();
        private JLabel titleLabel = new JLabel();
        private GridBagLayout gridBagLayout2 = new GridBagLayout();
        private JLabel yourNameLabel = new JLabel();
        private JLabel emailAddressLabel = new JLabel();
        private JLabel replyToAddressLabel = new JLabel();
        private JLabel organisationLabel = new JLabel();
        private JTextField nameTextField = new JTextField();
        private JTextField emailAddressTextField = new JTextField();
        private JTextField replyAddressTextField = new JTextField();
        private JTextField organisationTextField = new JTextField();
        private JCheckBox attachSignatureCheckBox = new JCheckBox();
        private JTextField signatureTextField = new JTextField();
        private JButton chooseButton = new JButton();
        private JButton editCardButton = new JButton();
        private JCheckBox attachVCardCheckBox = new JCheckBox();
        private JLabel outgoingServerLabel = new JLabel();
        private JComboBox outgoingServerCombobox = new JComboBox();
        private JButton manageIdentitiesButton = new JButton();
        private JScrollPane accountsScrollPane = new JScrollPane();
        private JButton addAccountButton = new JButton();
        private JButton setAsDefaultButton = new JButton();
        private JButton removeAccountButton = new JButton();
        private JButton okButton = new JButton();
        private JButton cancelButton = new JButton();
        private JTree accountTree = new JTree();
        private JScrollPane accountSettingNameScrollPane = new JScrollPane();
        private JTextArea accountSettingTextArea = new JTextArea();
        private JLabel accountNameLabel = new JLabel();
        private JTextField accountNameTextField = new JTextField();
     
        public MyPanel() {
            initGui();
        }
     
        private void initGui() {
            this.setLayout(gridBagLayout1);
            this.setSize(new Dimension(626, 474));
            defautIdentityPanel.setBorder(BorderFactory.createTitledBorder("Default Identity"));
            defautIdentityPanel.setLayout(gridBagLayout2);
            titleLabel.setText("Each account has an identity, wich is the information .... ");
            yourNameLabel.setText("Your Name :");
            emailAddressLabel.setText("Email Address :");
            replyToAddressLabel.setText("Reply to address :");
            organisationLabel.setText("Organisation :");
            attachSignatureCheckBox.setText("Attach this signature :");
            attachSignatureCheckBox.setMargin(new Insets(0, 0, 0, 0));
            signatureTextField.setMinimumSize(new Dimension(100, 20));
            signatureTextField.setPreferredSize(new Dimension(300, 20));
            chooseButton.setText("Choose ...");
            editCardButton.setText("Edit Card...");
            attachVCardCheckBox.setText("Attach my VCard to messages");
            outgoingServerLabel.setText("Outgoing Server (SMTP) :");
            manageIdentitiesButton.setText("Manage Identities ...");
            addAccountButton.setText("Add Account...");
            setAsDefaultButton.setText("Set as Default");
            removeAccountButton.setText("Remove Account");
            okButton.setText("OK");
            cancelButton.setText("Cancel");
            accountSettingNameScrollPane.setPreferredSize(new Dimension(2, 40));
            accountSettingTextArea.setBackground(new Color(255, 255, 181));
            accountSettingTextArea.setText("Account Setting - <account name>");
            accountSettingTextArea.setFont(new Font("Verdana", 0, 20));
            accountNameLabel.setText("Account Name :");
            accountNameTextField.setMinimumSize(new Dimension(125, 20));
            accountNameTextField.setPreferredSize(new Dimension(175, 20));
            defautIdentityPanel.add(titleLabel,
                                    new GridBagConstraints(0, 0, GridBagConstraints.REMAINDER,
                                                           1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
                                                           new Insets(5, 5, 5, 5),
                                                           0, 0));
            defautIdentityPanel.add(yourNameLabel,
                                    new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                                                           new Insets(5, 5, 0, 0),
                                                           0, 0));
            defautIdentityPanel.add(emailAddressLabel,
                                    new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                                                           new Insets(5, 5, 0, 0),
                                                           0, 0));
            defautIdentityPanel.add(replyToAddressLabel,
                                    new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                                                           new Insets(5, 5, 0, 0),
                                                           0, 0));
            defautIdentityPanel.add(organisationLabel,
                                    new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                                                           new Insets(5, 5, 0, 0),
                                                           0, 0));
            defautIdentityPanel.add(nameTextField,
                                    new GridBagConstraints(1, 1, GridBagConstraints.REMAINDER,
                                                           1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                                                           new Insets(3, 5, 0, 5),
                                                           0, 0));
            defautIdentityPanel.add(emailAddressTextField,
                                    new GridBagConstraints(1, 2, GridBagConstraints.REMAINDER,
                                                           1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                                                           new Insets(3, 5, 0, 5),
                                                           0, 0));
            defautIdentityPanel.add(replyAddressTextField,
                                    new GridBagConstraints(1, 3, GridBagConstraints.REMAINDER,
                                                           1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                                                           new Insets(3, 5, 0, 5),
                                                           0, 0));
            defautIdentityPanel.add(organisationTextField,
                                    new GridBagConstraints(1, 4, GridBagConstraints.REMAINDER,
                                                           1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
                                                           new Insets(3, 5, 0, 5),
                                                           0, 0));
            defautIdentityPanel.add(attachSignatureCheckBox,
                                    new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                                                           new Insets(10, 5, 0, 0),
                                                           0, 0));
            defautIdentityPanel.add(signatureTextField,
                                    new GridBagConstraints(0, 6, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
                                                           new Insets(3, 25, 0, 5),
                                                           0, 0));
            defautIdentityPanel.add(chooseButton,
                                    new GridBagConstraints(2, 6, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL,
                                                           new Insets(3, 0, 0, 5),
                                                           0, 0));
            defautIdentityPanel.add(editCardButton,
                                    new GridBagConstraints(2, 7, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL,
                                                           new Insets(3, 0, 0, 5),
                                                           0, 0));
            defautIdentityPanel.add(attachVCardCheckBox,
                                    new GridBagConstraints(0, 7, 2, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                                                           new Insets(5, 5, 0, 0),
                                                           0, 0));
            defautIdentityPanel.add(outgoingServerLabel,
                                    new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                                                           new Insets(8, 5, 0, 0),
                                                           0, 0));
            defautIdentityPanel.add(outgoingServerCombobox,
                                    new GridBagConstraints(1, 8, GridBagConstraints.REMAINDER,
                                                           1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                                                           new Insets(5, 5, 5, 5),
                                                           0, 0));
            this.add(defautIdentityPanel,
                     new GridBagConstraints(1, 2, 4, 1, 0.6, 0.0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                                            new Insets(5, 5, 5, 5), 0, 0));
            this.add(manageIdentitiesButton,
                     new GridBagConstraints(3, 3, GridBagConstraints.REMAINDER,
                                            1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
                                            new Insets(10, 0, 0, 10), 0, 0));
            accountsScrollPane.getViewport().add(accountTree, null);
            this.add(accountsScrollPane,
                     new GridBagConstraints(0, 0, 1, 4, 0.4, 1.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                                            new Insets(5, 5, 5, 5), 0, 0));
            this.add(addAccountButton,
                     new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                                            new Insets(0, 5, 0, 5), 0, 0));
            this.add(setAsDefaultButton,
                     new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                                            new Insets(5, 5, 0, 5), 0, 0));
            this.add(removeAccountButton,
                     new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                                            new Insets(5, 5, 0, 5), 0, 2));
            this.add(okButton,
                     new GridBagConstraints(4, 7, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
                                            new Insets(5, 0, 5, 5), 0, 0));
            this.add(cancelButton,
                     new GridBagConstraints(3, 7, 1, 1, 0.1, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
                                            new Insets(5, 5, 0, 5), 0, 0));
            accountSettingNameScrollPane.getViewport().add(accountSettingTextArea, null);
            this.add(accountSettingNameScrollPane,
                     new GridBagConstraints(1, 0, GridBagConstraints.REMAINDER,
                                            1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                                            new Insets(5, 5, 0, 5), 0, 0));
            this.add(accountNameLabel,
                     new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                                            new Insets(10, 5, 3, 0), 0, 0));
            this.add(accountNameTextField,
                     new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                                            new Insets(8, 5, 0, 5), 0, 0));
        }
     
        public static void main(String[] args) {
            JFrame myFrame = new JFrame("GridBagLayout power");
            myFrame.add(new MyPanel());
            myFrame.pack();
            myFrame.setLocationRelativeTo(null);
            myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            myFrame.setVisible(true);
        }
    }

    chacun sa facon d'utiliser le GridBagLayout.
    faut avouer aussi que parfois l'utilisation d'un IDE simplifie comme j'ai fait la
    au moin le code est plus lisible qu'avec matisse
    Images attach�es Images attach�es  

  8. #8
    Membre �m�rite
    Avatar de bbclone
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    537
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 537
    Par d�faut
    Elendhil,

    je sais pas si tu comprent mieu quand utiliser le GridBagLayout?
    tu voit dans ma fenetre j'ai au total que 2 panel.
    un panel global et un sous panel tu vois les composant ont pas tous les meme taille. il sont pas tous aligner au meme endroit
    si tu veux faire ca avec sans gridBagLayout tu doit alors diviser en plein de petit panel, c'est long a faire et aussi difficile a maintenir.

    avec le GridBagLayout 2-3 panel suffisent pour faire des interface complexe sans devoir diviser en sous panel. (j'ai diviser moi en deux panel, mais ce n'�tais pas obliger. j'aurai pu tout faire dans un seul panel).

    tu vois?

  9. #9
    Membre �clair�
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    351
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 351
    Par d�faut
    Je precise je suis debutant en java enfin meme en programmation.

    Donc en faite le code que je vois au dessus , tu la fais grace a un logiciel ou tu places les composants , une fois que tu as fait la disposition de tes composants et non plein de jpanel.

    Ton environement de travail te sort le code qui correspond . Ensuite ta plus qu'a coder les actions.

    C'est sur qu'avec ca tu as meme plus besoin de savoir comment marche le GridBagLayout. J'aime pas trop le principe , c sur ca doit etre plus rapide.

    Mais moi qui code avec mes petites mains si je dois placer mes composants en creant chaque contraintes avec les ancres , les valeurs pour savoir si il s'etale en H ou V ou les 2 ect..., les espaces entre chaque composants + les valeurs de placements(x,y,nbCelllargeur,nbCellhauteur, poidx,poidy ) , et tous ca pour chacun de mes composants.

    La ca devient quand meme tendu .....

    La methode qu' expliqu� Calo et nicotine , n'utilise que les valeurs de placements et les poids selon ton petit schema que tu fais avant.
    et toutes les containtes ont c.fill = c.both

    Donc pour placer des JPanels c tres simple(enfin une fois que tu as compris le principe).

    Mais le probleme c'est que quand tu places des composants dans les JPanels tout se deforme .
    C'est la que je comprend pas, car apparament Calo a fait une interface complexe comme ca ....

    Evidement avec ta methode ca peux pas se deformer je pense , vu que les containtes sont bcp plus strictes.

    Moi je pensais qu'une fois les Jpanels plac�s avec les contraintes de la methode a calo, ils pouvaient plus se deformer , qu'ils gardent tjrs la dispo de depart.....

  10. #10
    Membre �m�rite
    Avatar de bbclone
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    537
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 537
    Par d�faut
    moi aussi je fait pas du java depuis tres longtemps. je suis aussi un debutant.

    quand ce sont de petite interface je fais aussi tout les contrainte a la main. mais faut etre honnete avec un outil c'est beaucoup plus rapide quand on sait comment il marche pour faire de grande interface avec beaucoup de composant.

    l'interface que j'ai fait je l'ai fait en environ 10 minute. mais pour pouvoir utiliser l'outil tu as besoin de tres bien savoir comment fonctionne le gridBagLayout.
    parce que sur chaque composant que tu ajoute a ton panel tu doit definir tes contrainte mais au lieu de le faire dans le code tu le fais dans un assistant.
    regarde comment ca marche la-> http://blogs.jetbrains.com/yole/

    c'est pas encore dans les version "publique" d'idea ca arrive bientot :-)

    d'autre IDE font ca aussi. JBuilder et NetBeans font ca.
    mais je repete que tu dois tres bien savoir comment le gridBagLayout fonctionne pour les utiliser efficacement ces outils.

    connaitre les differente valeurs que peuvent prendre les attributs de ta GridBagConstraint et tu les saisis dans un assistant et puis voila, en quelque minute tu a une interface qui risque de te prendre des heure si tu divise en beaucoup de panel et que tu tappe tout.

  11. #11
    Membre �clair� Avatar de nicotine002
    Profil pro
    Inscrit en
    D�cembre 2005
    Messages
    577
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : D�cembre 2005
    Messages : 577
    Par d�faut
    Je me permet de r�pondre au sujet du redimmensionnement,
    tu peux tr�s bien d�finir un NONE sur tes contrainte, pourquoi ne le pourrais tu pas?Par exemple, si tu veux qu'un de tes composants ne sois pas redimensionnable, m�me un container(mais bon l� je ne vois plus l'utilit� d'utiliser un LayoutManager, autant le mettre � null), tu fais ceci:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    switch(i){
    		case 0: getContentPane().add( pan1, c );c.fill=c.NONE;break;
    		case 1: getContentPane().add( pan2, c );c.fill=c.BOTH ;break;
    		case 2: getContentPane().add( pan3, c ); break;
    		case 3: getContentPane().add( pan4, c ); break;
    		case 4: getContentPane().add( pan5, c ); break;
    		case 5: getContentPane().add( pan6, c ); break;
    		     }
    Ici ton pan2 ne sera pas redimesionnable.et tu peux faire ceci pour les components �galement tels que les JTextArea,Field ,JLabel etc...
    Cette m�thode ne "bride" en rien les capacit�s du GridBag, tu peux faire autant de choses que si tu le faisait "� la main".Idem pour celle de bbclone, ce ne sont juste que des astuces qui te permettent de r�aliser plus rapidement tes Layouts.
    Ps: il y a �galment une class dans la FAQ qui te permet de r�aliser ce genre de choses plus rapidement.

  12. #12
    Membre �m�rite
    Avatar de bbclone
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    537
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 537
    Par d�faut
    il y a comme ca des "common practices" quand on utilise le GridBagLayout.

    par exemple
    - souvent on met fill.HORIZONAL a un textField quand il es GridBagConstraints.REMAINDER sans weight.
    - souvent on met fill.BOTH a un scrollPane en lui mettant un weightx et weighty de 1.
    - seul quelque composant sont agrandi quand la fenetre est aggrandie (le dernier composant de la grille en horizontal un scrollPane en horizontal et vertical)
    - il faut eviter les padding autant que possible

    ...

    Elendhil,
    si t'a des question sur le GridBagLayout pose les.
    si tu sais pas ce que veut dire une contrainte ou les differente valeur qu'on peut utiliser ou n'importe quoi vas y demande!

  13. #13
    Membre chevronn�
    Homme Profil pro
    Ing�nieur d�veloppement logiciels
    Inscrit en
    Avril 2004
    Messages
    253
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 47
    Localisation : France, Haute Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : Ing�nieur d�veloppement logiciels
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Avril 2004
    Messages : 253
    Par d�faut
    Il est vrai qu'avec un GridBagLayout, on b�n�ficie d'une souplesse tr�s importante au d�triment cependant de la facilit� d'utilisation...
    Imagine que tu veuilles modifier ton layout pour ins�rer un composant; si tu n'a pas param�tr� les coordonn�es, il te faut tout renum�roter!!

    Il existe une alternative au GridBagLayout. Un layout � la fois tr�s simple d'utilisation et tout aussi puissant que GBL: le ZoneLayout. Il s'agit d'une API LGPL que vous trouverez � l'adresse suivante : http://www.zonelayout.com
    Il y a m�me un comparatif avec le GBL...
    A vous de juger.

Discussions similaires

  1. [CR] mise en forme d'un champs texte en fonction des donn�es
    Par niPrM dans le forum SAP Crystal Reports
    R�ponses: 6
    Dernier message: 29/06/2004, 11h57
  2. [CR 9] Mise en forme non affich�e when null
    Par Yorglaa dans le forum Formules
    R�ponses: 2
    Dernier message: 28/06/2004, 17h27
  3. mise en forme rapide d'applets
    Par appletj dans le forum Applets
    R�ponses: 11
    Dernier message: 03/06/2004, 13h28
  4. Mise en forme HTML
    Par Regis.C dans le forum XML/XSL et SOAP
    R�ponses: 5
    Dernier message: 25/04/2004, 11h55
  5. Mise en forme fichier avant Import
    Par jeff37 dans le forum Langage SQL
    R�ponses: 3
    Dernier message: 21/04/2004, 15h16

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