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 78 79 80
|
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JColorChooser;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.util.*;
public class main {
public static void main(String[] args) {
JFrame fenetre = new JFrame();
fenetre.setSize(800,600);
fenetre.setTitle("test");
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setLocationRelativeTo(null);
fenetre.setResizable(false);
fenetre.setVisible(true);
JPanel cardCreation = new JPanel(new GridBagLayout());
cardCreation.setBackground(Color.blue);
GridBagConstraints gc = new GridBagConstraints();
String[] messageStrings = {"1", "2", "3", "4", "5", "6"};
JComboBox cmbMessageList = new JComboBox<String>(messageStrings);
JButton boutonAjouter = new JButton("Ajouter");
JButton boutonGenerer = new JButton("Générer");
JTextArea textCreation = new JTextArea("je voudrai mettre du texte ici lalala");
JScrollPane spCreation = new JScrollPane(textCreation);
gc.gridx = 1;
gc.gridy = 0;
gc.gridwidth = 1;
gc.gridheight = 1;
gc.weightx = 0;
gc.weighty = 1;
gc.anchor = GridBagConstraints.PAGE_START;
cardCreation.add(cmbMessageList, gc);
gc.gridx = 2;
gc.gridy = 0;
cardCreation.add(boutonAjouter, gc);
gc.gridx = 3;
gc.gridy = 0;
cardCreation.add(boutonGenerer, gc);
//juste ces 3 boutons, sans le jscrollpane, sont alignés
//en haut au milieu mais dès que l'on ajoute le suivant ça décalle tout
gc.gridx = 3;
gc.gridy = 2;
gc.gridwidth = 2; //2 columns wide
gc.anchor = GridBagConstraints.LAST_LINE_END;
cardCreation.add(spCreation, gc);
fenetre.add(cardCreation, BorderLayout.CENTER);
fenetre.setVisible(true);
}
} |
Partager