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

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  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

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