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

AWT/Swing Java Discussion :

Problème de juxtaposition de JPanel


Sujet :

AWT/Swing Java

  1. #1
    Membre régulier
    Inscrit en
    Décembre 2006
    Messages
    196
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 196
    Points : 89
    Points
    89
    Par défaut Problème de juxtaposition de JPanel
    Bonjour à tous,

    J'ai un problème tous bête :
    J'ai une JFrame dans laquelle j'ai ajouté un JPanel.
    Ensuite j'ajoute dans mon JPanel un JScrollPane et un autre JPanel que nous appelerons JPanel2. Mes fenetres s'affiche sauf que le contenu de mon Jpanel2 ne s'affiche pas.

    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
     
    JPanel mainPanel = new JPanel();
     
    setTitle( "Basic JTable in a JPanel" );
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
     
    JTable jTable = new JTable( new ModelStaticObject() );
    jTable.setDefaultRenderer( Boolean.class, new GenderCellRenderer() );
    jTable.setDefaultRenderer( Color.class, new ColorCellRenderer() );
    jTable.getColumnModel().getColumn(1).setCellRenderer( new BoldCellRenderer() );
     
    mainPanel.setLayout( new BorderLayout() );
     
    JScrollPane jScrollPane = new JScrollPane( jTable );
    jScrollPane.setBorder( new LineBorder(Color.RED) );
    jScrollPane.setPreferredSize( new Dimension( 700,500 ) );
    mainPanel.add( jScrollPane, BorderLayout.CENTER );
     
    EastPanel eastPanel = new EastPanel("EastPanel");
    eastPanel.setPreferredSize( new Dimension( 700,200 ) );
    mainPanel.add( eastPanel, BorderLayout.NORTH );
     
    this.setContentPane( mainPanel );
    this.setVisible(true);
    pack();
    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
     
    package com.clearstream.main;
     
    import java.awt.GridBagConstraints;
    import java.awt.Insets;
     
    public class EastPanel extends JPanel {
     
    	private static final long serialVersionUID = 1L;
     
    	public JPanel eastPanel = new JPanel();
    	public JLabel matriculeLabel = new JLabel("Matricule :");
    	public JLabel nomLabel = new JLabel("Nom :");
    	public JLabel prenomLabel = new JLabel("Prénom :");
    	public JLabel fonctionLabel = new JLabel("Fonction :");
    	public JLabel sexeLabel  = new JLabel("Sexe :");
    	public GridBagConstraints gbc = new GridBagConstraints();
     
    	public EastPanel(String name) { 
    		initPanel(name);
    	}
     
    	public void initPanel(String name) {
    		this.setName(name);
    		//this.eastPanel.setLayout( new GridBagLayout() );
     
    		/* a- ajout du label contenant le matricule. */
    		this.gbc.gridx = 0;
    		this.gbc.gridy = 0;
    		this.gbc.gridwidth = GridBagConstraints.REMAINDER; // gbc.gridheight = 1;
    		this.gbc.insets = new Insets(0, 5, 0, 0);
    		/* Le point d'ancrage ici n'a pas une grande importance. Nous allons quand même essayer d'aligner tout les
    		 * composants qui le peuvent sur leur ligne de base. */
    		this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		this.eastPanel.add(this.matriculeLabel, gbc);
     
    		/* c- étiquette contenant le nom. */
    		this.gbc.gridx = 1;
    		this.gbc.gridy = 1;
    		this.gbc.gridwidth = 1;
    		this.gbc.gridheight = 1;
    		/* L'étiquette avec le nom sera alignée sur la ligne de base avec le champ de saisie pour le nom. */
    		this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		this.gbc.insets = new Insets(0, 5, 0, 0);
    		this.eastPanel.add(this.nomLabel, gbc);
     
    	    /* e- l'étiquette pour le prénom. */
    		this.gbc.gridx = 1;
    		this.gbc.gridy = 2;
    		this.gbc.gridwidth = 1;
    		this.gbc.gridheight = 1;
    		this.gbc.fill = GridBagConstraints.NONE;
    		this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		this.gbc.insets = new Insets(0, 5, 0, 0);
    	    this.eastPanel.add(this.prenomLabel, gbc);
     
    	    /* g- l'étiquette pour la fonction. */
    	    this.gbc.gridx = 1;
    	    this.gbc.gridwidth = 1;
    	    this.gbc.gridheight = 1;
    	    this.gbc.gridy = 3;
    	    this.gbc.fill = GridBagConstraints.NONE;
    	    this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    	    this.gbc.insets = new Insets(0, 5, 0, 0);
    	    this.eastPanel.add(this.fonctionLabel, gbc);
     
    	}
    }
    Si quelqu'un a une petite idée merci d'avance

  2. #2
    Membre régulier
    Inscrit en
    Décembre 2006
    Messages
    196
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 196
    Points : 89
    Points
    89
    Par défaut
    Bonsoir à tous,

    J'ai trouvé mon erreur. J'avais pas les yeux en face des trous.
    Ma deuxième Classe hérite de Jpanel donc c'est déjà un Jpanel et j'en recrée un à l'intérieur que ne n'affiche jamais du coup.

    Comme ça c'est mieux:

    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
     
    package com.clearstream.main;
     
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
     
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
    public class EastPanel extends JPanel {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
     
    	public JLabel matriculeLabel = new JLabel("Matricule :");
    	public JLabel nomLabel = new JLabel("Nom :");
    	public JLabel prenomLabel = new JLabel("Prénom :");
    	public JLabel fonctionLabel = new JLabel("Fonction :");
    	public JLabel sexeLabel  = new JLabel("Sexe :");
    	public GridBagConstraints gbc = new GridBagConstraints();
     
    	public EastPanel(String name) { 
    		initPanel(name);
    	}
     
    	public void initPanel(String name) {
    		this.setName(name);
    		this.setLayout( new GridBagLayout() );
     
    		this.gbc.gridx = 0;
    		this.gbc.gridy = 0;
    		this.gbc.gridwidth = GridBagConstraints.REMAINDER; // gbc.gridheight = 1;
    		this.gbc.insets = new Insets(0, 5, 0, 0);
    		this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		this.add(this.matriculeLabel, gbc);
     
    		this.gbc.gridx = 1;
    		this.gbc.gridy = 1;
    		this.gbc.gridwidth = 1;
    		this.gbc.gridheight = 1;
    		this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		this.gbc.insets = new Insets(0, 5, 0, 0);
    		this.add(this.nomLabel, gbc);
     
    	    this.gbc.gridx = 1;
    		this.gbc.gridy = 2;
    		this.gbc.gridwidth = 1;
    		this.gbc.gridheight = 1;
    		this.gbc.fill = GridBagConstraints.NONE;
    		this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		this.gbc.insets = new Insets(0, 5, 0, 0);
    	    this.add(this.prenomLabel, gbc);
     
    	    this.gbc.gridx = 1;
    	    this.gbc.gridwidth = 1;
    	    this.gbc.gridheight = 1;
    	    this.gbc.gridy = 3;
    	    this.gbc.fill = GridBagConstraints.NONE;
    	    this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    	    this.gbc.insets = new Insets(0, 5, 0, 0);
    	    this.add(this.fonctionLabel, gbc);
     
    	    this.gbc.gridy = 4;
    	    this.gbc.gridx = 1;
    	    this.gbc.gridwidth = 1;
    	    this.gbc.gridheight = 1;
    	    this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    	    this.gbc.insets = new Insets(0, 5, 0, 0);
    	    this.add(this.sexeLabel, gbc);
     
    	    this.setPreferredSize( new Dimension( 700,200 ) );
    	}
    }

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

Discussions similaires

  1. problème de dimension de JPanel
    Par Virgile le chat dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 10/06/2008, 11h07
  2. Problème de switch de JPanel
    Par L0007 dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 21/05/2008, 15h06
  3. Probléme avec déplacement de JPanel
    Par evie62 dans le forum AWT/Swing
    Réponses: 5
    Dernier message: 16/01/2007, 10h38
  4. Problème avec GridBagLayout dans JPanel
    Par caneman dans le forum AWT/Swing
    Réponses: 4
    Dernier message: 19/12/2006, 22h32
  5. Problème avec image dans JPanel
    Par littleshrimp dans le forum AWT/Swing
    Réponses: 7
    Dernier message: 14/05/2006, 14h05

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