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 :

probleme de GridBagLayout


Sujet :

Interfaces Graphiques en Java

  1. #1
    Candidat au Club
    Homme Profil pro
    �tudiant
    Inscrit en
    Mai 2014
    Messages
    2
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activit� : �tudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2014
    Messages : 2
    Par d�faut probleme de GridBagLayout
    Bonjour,
    Je suis d�butant en Java et je voudrais r�aliser une interface graphique,le probl�me que je voudrais que les boutons a partir de verre 3 ce place juste en dessous de ceux en haut
    Merci.

    Nom : Sans titre.png
Affichages : 73
Taille : 55,3 Ko

    Voila le code que j'ai utilis�:

    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
    package exemple;
     
    import java.awt.Dimension;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.GridBagConstraints;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.ImageIcon;
     
    public class exemple {
     
    	private JFrame mainFrame = null;
     
    	public exemple() {
            mainFrame = new JFrame("Suivi Production");
            mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            /* 1- Initialisation du container. */
            mainFrame.setLayout(new GridBagLayout());
     
            /* 2- Création et initialisation d'une série de composants. */
            JButton verre1Button = new JButton("Verre 1");
            JButton verre3Button = new JButton("Verre 3");
            JButton verre4Button = new JButton("Verre 4");
            JButton pet1Button = new JButton("Pet 1");
            JButton histoButton = new JButton("Historique");
            JButton impButton = new JButton("Imprimer");
            verre1Button.setPreferredSize(verre3Button.getPreferredSize());
            verre4Button.setPreferredSize(verre3Button.getPreferredSize());
            pet1Button.setPreferredSize(verre3Button.getPreferredSize());
            JLabel lab = new JLabel(new ImageIcon("src\\téléchargemen.jpg")); 
     
            /*3- Ajout de ces composants en spécifiant les contraintes de type GridBagConstraints. */
            GridBagConstraints gbc = new GridBagConstraints();
     
            gbc.gridx = gbc.gridy = 0;
            gbc.gridheight = gbc.gridwidth = 1;
            gbc.anchor = GridBagConstraints.BASELINE_LEADING;
            gbc.insets = new Insets(10, 10, 10, 10);
            mainFrame.add(verre1Button, gbc);
     
            gbc.gridx = 1;
            gbc.gridy = 0;
            gbc.gridheight = 1; 
            gbc.gridwidth = 1;
            gbc.anchor = GridBagConstraints.BASELINE_LEADING;
            gbc.insets = new Insets(10, 10, 10, 10);
            mainFrame.add(lab, gbc);
     
            gbc.gridx = 2;
            gbc.gridy = 0;
            gbc.gridheight = gbc.gridwidth = 1;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.anchor = GridBagConstraints.BASELINE_LEADING;
            gbc.insets = new Insets(10, 10, 10, 10);
            mainFrame.add(histoButton, gbc);
     
            gbc.gridx = 0;
            gbc.gridy = 1;
            gbc.gridheight = 1;
            gbc.anchor = GridBagConstraints.BASELINE_LEADING;
            gbc.fill = GridBagConstraints.NONE;
            gbc.insets = new Insets(10, 10, 10, 10);
            mainFrame.add(verre3Button, gbc);
     
            gbc.gridx = 2;
            gbc.gridy = 1;
            gbc.gridheight = gbc.gridwidth = 1;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.anchor = GridBagConstraints.BASELINE_LEADING;
            gbc.insets = new Insets(10, 10, 10, 10);
            mainFrame.add(impButton, gbc);
     
            gbc.gridx = 0;
            gbc.gridy = 2;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.anchor = GridBagConstraints.BASELINE_LEADING;
            gbc.fill = GridBagConstraints.NONE;
            gbc.insets = new Insets(10, 10, 10, 10);
            mainFrame.add(verre4Button, gbc);
     
            gbc.gridx = 0;
            gbc.gridy = 3;
            gbc.gridheight = 1;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.anchor = GridBagConstraints.BASELINE_LEADING;
            gbc.fill = GridBagConstraints.NONE;
            gbc.insets = new Insets(10, 10, 10, 10);
            mainFrame.add(pet1Button, gbc);
     
            mainFrame.setMinimumSize(new Dimension(500, 500));
            mainFrame.setLocationRelativeTo(null);
        }
     
        public void setVisible(boolean b) {
            mainFrame.setVisible(b);
        }
     
    	public static void main(String[] args) {
     
                    exemple mp = new exemple();
                    mp.setVisible(true);
     
     
    	}
     
    }

  2. #2
    Expert �minent
    Avatar de tchize_
    Homme Profil pro
    Ing�nieur d�veloppement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 46
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par d�faut
    Tu peux faire un croquis de ce que tu veux, parce que, pour moi, ce n'est pas clair?

  3. #3
    Candidat au Club
    Homme Profil pro
    �tudiant
    Inscrit en
    Mai 2014
    Messages
    2
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activit� : �tudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2014
    Messages : 2
    Par d�faut
    Je voudrais qu'elle devienne comme �a

    Nom : Sans titre.png
Affichages : 88
Taille : 55,6 Ko:

  4. #4
    Expert �minent
    Avatar de tchize_
    Homme Profil pro
    Ing�nieur d�veloppement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 46
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par d�faut
    Donc, si je te suis bien, une colonne de boutons � gauche, une colonne � droite et un logo au centre.

    dans ce cas je partirais sur un BroderLayout principal, avec le logo en BorderLayout.CENTER, le panneau gauche enBorderLayout. WEST et le panneau droit en BorderLayout.EAST

    Ensuite, dans chacun des deux panneaux lat�ral, je travaillerais avec un BoxLayout vertical, tout simplement.

Discussions similaires

  1. Probleme avec GridBagLayout
    Par Konami15 dans le forum Agents de placement/Fen�tres
    R�ponses: 7
    Dernier message: 02/05/2009, 16h34
  2. Probleme GridBagLayout et defenition des tailles des JPanel
    Par thibaultG dans le forum AWT/Swing
    R�ponses: 2
    Dernier message: 12/11/2007, 20h32
  3. probleme avec GridBagLayout
    Par moi89 dans le forum AWT/Swing
    R�ponses: 2
    Dernier message: 09/05/2006, 12h03
  4. [GridbagLayout] probleme de taille de composants.
    Par berg dans le forum AWT/Swing
    R�ponses: 1
    Dernier message: 17/03/2006, 22h06
  5. [Swing] probleme de GridBagLayout
    Par calypso dans le forum Agents de placement/Fen�tres
    R�ponses: 4
    Dernier message: 13/04/2005, 17h26

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