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 :

Problème avec Layout GidBagLayout


Sujet :

Agents de placement/Fenêtres Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Décembre 2009
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations forums :
    Inscription : Décembre 2009
    Messages : 67
    Par défaut Problème avec Layout GidBagLayout
    Salut Tout le monde
    j'ai un problem avec gridbaglayout j'ai cré un JPanel avec GridBagLayout et je veut faire comme cela

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    *************
    *              *   *
    *      A      * B *
    *              *   *
    *************      
    *       C          *
    *************
    sachant que cette forme reste la même i on redimensionne la fenêtre voici on code mais sa marche pas vraiment super car par fois l'affichage est parfait parfois c'est catastrophique et voici mon code
    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
     
    public JPanel Construire(String name){
    		oldvalue = 0;
    		JTextPane DialogSalon = new JTextPane();
    		DialogSalon.setName(name);
    		TxtMap.put(name, DialogSalon);
    		setLayout(new GridBagLayout());
    		GridBagConstraints c = new GridBagConstraints();
                    //ici composant A qui est un jtextpane
    		c.anchor = GridBagConstraints.FIRST_LINE_START ;
    		c.gridx = 0 ;
    		c.gridy = 0;;
    		c.weightx = 10 ;
    		c.weighty = 100 ;
    		c.fill = GridBagConstraints.BOTH;
    		scrolpane = new JScrollPane();
    		DialogSalon.setAutoscrolls(true);
    		scrolpane.getViewport().add(DialogSalon);
    		scrolpane.getVerticalScrollBar().addAdjustmentListener(this);
                    scrolpane.getVerticalScrollBar().addMouseListener(this);
    	      scrolpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    		add(scrolpane,c);
    		//List Pseudo composant B
    		c.gridwidth = GridBagConstraints.REMAINDER ;
    		c.weightx = 1 ;
    		c.weighty = .0 ;
    		c.gridx = 1;
    		c.gridy = 0;
    		c.gridheight = 2;
    		add(PanelListPseudo(name),c);
                    //composant C
    		c.weightx = .0 ;
    		c.weighty = .0 ;
    		c.gridx = 0 ;
    		c.gridy = 2;
    		c.gridwidth = GridBagConstraints.REMAINDER ;
    		c.gridheight = GridBagConstraints.REMAINDER ;
    		c.fill = GridBagConstraints.BOTH;
    		c.anchor = GridBagConstraints.LAST_LINE_START;
    		add(PanelBarre(),c);
    		RightPanel.AddPanel(this,getName());
    		return this ;
    	}

  2. #2
    Membre Expert Avatar de Ivelios
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juillet 2008
    Messages
    1 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 031
    Par défaut
    Je ne vois pas l'erreur dans ton code.

    En voila un qui marche :
    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
    import java.awt.*;
    import javax.swing.*;
     
     
    public class Dessin extends JPanel{
     
        private GridBagLayout layout = new GridBagLayout();
        private GridBagConstraints gbc= new GridBagConstraints();
     
        public Dessin(){
     
            this.setLayout(layout);
     
            //Configuration du GridBagLayout
            gbc.insets = new Insets(5, 5, 5, 5);
            gbc.fill = GridBagConstraints.BOTH;
            gbc.anchor =  GridBagConstraints.LINE_START;
     
            //Composants
            JPanel hg = new JPanel();
            JPanel hd = new JPanel();
            JPanel b = new JPanel();
     
            //Couleurs des composants
            hg.setBackground(Color.red);
            hd.setBackground(Color.yellow);
            b.setBackground(Color.blue);
     
     
            this.ajouterComposant(hg, 0,0,1,1,0.7f,1);
            this.ajouterComposant(hd, 0,1,1,1,0.3f,1);
            this.ajouterComposant( b, 1,0,2,2,1,1);
     
        }
     
        /** Ajoute un composent */
        private void ajouterComposant(JComponent composant, int ligne, int colonne,int gridheight,int gridwidth,float wX, float wY){
            gbc.gridy = ligne;
            gbc.gridx = colonne;
            gbc.gridheight = gridheight;
            gbc.gridwidth = gridwidth;
            gbc.weightx = wX;
            gbc.weighty = wY;
     
            layout.setConstraints(composant, gbc);
            this.add(composant);
        }
     
     
     
        public static void main(String[] args){
            JFrame f = new JFrame("BagLayout");
            f.setSize(300,300);
            f.setContentPane(new Dessin());
            f.setVisible(true);
        }
     
    }

Discussions similaires

  1. Problème avec layout en SWT
    Par talkhor dans le forum Agents de placement/Fenêtres
    Réponses: 3
    Dernier message: 22/08/2007, 18h25
  2. [Struts-Layout] problème avec layout:collection
    Par khayri dans le forum Struts 1
    Réponses: 4
    Dernier message: 31/05/2007, 14h28
  3. problème avec layout:menu
    Par khayri dans le forum Struts 1
    Réponses: 1
    Dernier message: 23/04/2007, 20h17
  4. [Struts-Layout] problème avec layout:datagrid
    Par khayri dans le forum Struts 1
    Réponses: 2
    Dernier message: 20/04/2007, 10h31
  5. [JscrollPane]Problèmes avec layout du panel intérieur
    Par Baptiste Wicht dans le forum AWT/Swing
    Réponses: 14
    Dernier message: 19/03/2006, 14h08

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