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 Disposition JPanel


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Février 2010
    Messages
    29
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 29
    Par défaut Problème Disposition JPanel
    Bonjour je vous explique mon problème.
    J'ai une JFrame qui comporte un JPanel.
    Dans ce JPanel j'ajoute deux JPanel. Ces JPanel sont ajoutés à l'aide d'un GridBagLayout.
    Mon problème est que ces JPanel sont décalés par rapport au haut de ma JFrame. Cet espace est de 33 pixels (voir set Bounds des deux panel). Lorsque j'enlève l'instruction -33 Pixels les Panels sont bien aligné sur le haut de ma JFrame.

    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
     
    this.panelPlanScenario = new PanelPlanScenario(this.imagePath,(String)this.comboBox.getSelectedItem());
    			this.panelPlanScenario.setBounds(0,0,this.getWidth()*3/4, this.getHeight()-33);
     
    			this.panelCreationScenario = new PanelCreationScenario((String)this.comboBox.getSelectedItem(), (String)this.comboBoxScenario.getSelectedItem(), this, this.panelPlanScenario);
    			this.panelCreationScenario.setBounds(this.getWidth()*3/4,0,this.getWidth()/4-33, this.getHeight()-33); //Problème avec les -33 pixels
     
    			JScrollPane js = new JScrollPane(this.panelCreationScenario);
    			JScrollPane scroll = new JScrollPane(this.panelPlanScenario);
    			scroll.setAutoscrolls(true);
    			scroll.setSize(this.panelPlanScenario.getSize());
    			scroll.setPreferredSize(this.panelPlanScenario.getSize());
    			scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    			scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scroll.setViewportBorder(new LineBorder(Color.RED));
     
    			js.setAutoscrolls(true);
    			js.setSize(this.panelCreationScenario.getSize());
    			js.setPreferredSize(this.panelCreationScenario.getSize());
    			js.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    			js.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			js.setViewportBorder(new LineBorder(Color.RED));
    			js.setBounds(this.getWidth()*3/4,0,this.getWidth()/4-100,this.getHeight()-33);
     
    			this.setLayout(new GridBagLayout());
     
     
    			this.setLayout(new GridBagLayout());
    			GridBagConstraints c = new GridBagConstraints();
    			c.fill = GridBagConstraints.VERTICAL;
    			c.anchor = GridBagConstraints.NORTH;
    			c.gridx = 0;
    			c.gridy = 0;
    			this.add(scroll,c);
    			c.gridx = 1;
    			this.add(js,c);
    		//	this.repaint();
    			this.validate();
    Je vousdrais savoir s'il était possible de pouvoir aligner ces JPanel sur le haut de ma Jframe tout en réduisant leur taille. J'ai essayé un GridBagCOnstraint anchor NORTH mais rien ne fait.

    Merci d'avance

  2. #2
    Membre éclairé
    Homme Profil pro
    Ingénieur Informatique et Réseaux
    Inscrit en
    Avril 2011
    Messages
    232
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur Informatique et Réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 232
    Par défaut
    Bonjour,
    Je n'ai pas vraiment compris ton problème mais ton code avec le layout est assez bizard: le GridBagConstraints que tu utilises pour ajouter ton 2ème JPanel est le même object que pour le 1er, donc quand tu changes le gridx, ça le change pour le 1er aussi.

    Je te propose ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.VERTICAL;
    c.anchor = GridBagConstraints.NORTH;
    c.gridx = 0;
    c.gridy = 0;
    this.add(scroll,c);
    c = new GridBagConstraints();
    c.fill = GridBagConstraints.VERTICAL;
    c.anchor = GridBagConstraints.NORTH;
    c.gridx = 1;
    c.gridy = 0;
    this.add(js,c);
    Pour tes problèmes de positionnement, un screen shot serait peut-être plus explicite.

Discussions similaires

  1. problème avec JPanel
    Par sky88 dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 04/08/2008, 15h04
  2. Problèmes performances JPanel rafraichissement images
    Par Mr.Cow dans le forum AWT/Swing
    Réponses: 5
    Dernier message: 23/05/2008, 19h14
  3. problème affichage JPanel dans un JPanel
    Par rburney dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 02/04/2008, 11h36
  4. [Form Builder] problème de JPanel et JTable
    Par syrius31 dans le forum NetBeans
    Réponses: 2
    Dernier message: 19/07/2007, 14h47
  5. Problème repaint JPanel
    Par anthony62 dans le forum AWT/Swing
    Réponses: 4
    Dernier message: 19/09/2006, 15h09

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