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:
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