Bonjour
je cherche à créer un conteneur JPanel auquel j'applique le gridbagLayout.
A ce panel je réjoute 2 controles:
un JLabel et un Jcombobox.
Je voudrais que le JCombobox prenne toute la largeur du JPanel. Voici le code généré par le form editor de netbeans:
Mais lorsque j'execute le code, si j'élargi le jpanel, et bien le jCombobox garde sa taille de base.
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 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; jLabel1 = new javax.swing.JLabel(); jComboBox1 = new javax.swing.JComboBox(); setLayout(new java.awt.GridBagLayout()); jLabel1.setText("Chargé d'affaire"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; add(jLabel1, gridBagConstraints); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; add(jComboBox1, gridBagConstraints); }// </editor-fold>
Je réalise la meme chose sous eclipse et la cela fonctionne.
le code généré avec Visual Editor de Eclipse
Quelqu'un pourrait-il me dire pourquoi j'obtiens cette différence de comportement, alors que la méthode employée est identique sur les 2 IDE? Ou comment faire pour que mon combobox j'étende correctement sur le panel avec netbeans?
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 private JPanel getJPanelChargeAffaire() { if (jPanelChargeAffaire == null) { jPanelChargeAffaire = new JPanel(); jPanelChargeAffaire.setSize(new Dimension(216, 223)); jPanelChargeAffaire.setLayout(new GridBagLayout()); GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.gridx = 0; gridBagConstraints1.fill = GridBagConstraints.NONE; gridBagConstraints1.gridy = 1; jPanelChargeAffaire.add(getLblChargeAffaire(), gridBagConstraints1); gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.fill = GridBagConstraints.BOTH; gridBagConstraints1.gridy = 2; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.gridx = 0; jPanelChargeAffaire.add(getJComboBox(), gridBagConstraints1); } return jPanelChargeAffaire; }
Merci d'avance
Partager