1 pièce(s) jointe(s)
Problème de GridBagLayout
Bonjour,
J'ai un souci pour comprendre comment fonctionne le GridBagLayout.
J'ai lu le tuto de votre site, je pensais avoir compris mais quand je vois le résultat que j’obtiens, ce n'est visiblement pas le cas.
Je vous mets mon code, un screen de ce que j'obtiens et je vous explique ensuite ce que j'espérais comme résultat.
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 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
| import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class ViewClient extends JFrame
{
private JFrame mainFrame = null;
public ViewClient()
{
initWindow();
}
private void initWindow()
{
JPanel jpLogin = new JPanel();
JPanel jpConversation = new JPanel();
JList jlLogin = new JList();
JTextArea jtaConversation = new JTextArea();
//Initialisation de la fenetre principale
mainFrame = new JFrame();
mainFrame.setTitle("Client");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setLayout(new GridBagLayout());
mainFrame.setVisible(true);
mainFrame.setSize(800, 500);
mainFrame.setLocationRelativeTo(null);
mainFrame.setResizable(false);
GridBagConstraints gbc = new GridBagConstraints();
//JPanel participants
jpLogin.setLayout(new BorderLayout());
jpLogin.add(jlLogin);
jpLogin.setBorder(BorderFactory.createTitledBorder("Participant(s)"));
gbc.gridx = gbc.gridy = 0;
gbc.gridheight = gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.PAGE_START;
gbc.weightx = 1.;
gbc.weighty = 1.;
gbc.fill = GridBagConstraints.HORIZONTAL;
mainFrame.add(jpLogin, gbc);
//JPanel conversation
jpConversation.setLayout(new BorderLayout());
jpConversation.add(jtaConversation);
jtaConversation.setEditable(false);
jpConversation.setBorder(BorderFactory.createTitledBorder("Conversation"));
gbc.gridx = 1;
gbc.gridwidth = 3;
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.PAGE_START;
gbc.fill = GridBagConstraints.HORIZONTAL;
mainFrame.add(jpConversation, gbc);
}
} |
Pièce jointe 209638
Voilà, j'aimerais que la partie "Participants" occupe 1/4 de la largeur de la page et que donc l'autre partie, "Conversation" occupe le reste. Et que les 2 parties occupent la totalité de la hauteur de la page.
De plus, ma JList ne s'affiche pas du tout dans la partie "participants" contrairement à ma JTextArea qui s'affiche (un peu) dans la partie de droite...
Pourriez-vous m'aider ?
Merci.