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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
public class TestInterface {
private JFrame fenetre = new JFrame("Test");
private JPanel panelDroit = new JPanel(new BorderLayout());
private JTextField champTexte = new JTextField("Champ texte");
private JPanel panelImage = new JPanel();
private JPanel panelGauche = new JPanel(new BorderLayout());
private JPanel contenuPanelGauche = new JPanel();
private JLabel label1 = new JLabel("Label1");
private JComboBox combo1 = new JComboBox();
private JLabel label2 = new JLabel("Label2");
private JComboBox combo2 = new JComboBox();
private JLabel label3 = new JLabel("Label3");
private JComboBox combo3 = new JComboBox();
private JTable table = new JTable();
private JScrollPane scrollPane = new JScrollPane(table);
private JButton bouton1 = new JButton("Bouton1");
private JButton bouton2 = new JButton("Bouton1");
private JButton bouton3 = new JButton("Bouton1");
private JSlider slider = new JSlider();
public void initAndDisplay() {
fenetre.setLayout(new BorderLayout());
GridBagLayout gbl = new GridBagLayout();
contenuPanelGauche.setLayout(gbl);
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.NONE;
//init panel gauche labels combos
gbc.weightx = 0;
gbc.weighty = 0;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(5, 5, 5, 5);
contenuPanelGauche.add(label1, gbc);
gbc.gridx = 1;
contenuPanelGauche.add(combo1, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
contenuPanelGauche.add(label2, gbc);
gbc.gridx = 1;
contenuPanelGauche.add(combo2, gbc);
gbc.gridx = 0;
gbc.gridy = 2;
contenuPanelGauche.add(label3, gbc);
gbc.gridx = 1;
contenuPanelGauche.add(combo3, gbc);
//fin init panel gauche labels combos
//init panel gauche tableau
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.setColumnIdentifiers(new String[]{"Col1", "Col2"});
gbc.gridx = 0;
gbc.gridy = 3;
gbc.gridwidth = 2;
contenuPanelGauche.add(scrollPane, gbc);
//fin init panel gauche tableau
//init panel gauche boutons slider
gbc.gridx = 0;
gbc.gridy = 4;
gbc.gridwidth = 1;
contenuPanelGauche.add(bouton1, gbc);
gbc.gridx = 1;
contenuPanelGauche.add(bouton2, gbc);
gbc.gridx = 0;
gbc.gridy = 5;
gbc.gridwidth = 2;
contenuPanelGauche.add(slider, gbc);
gbc.gridx = 0;
gbc.gridy = 6;
contenuPanelGauche.add(bouton3, gbc);
//fin init panel gauche boutons slider
panelGauche.add(contenuPanelGauche, BorderLayout.NORTH);
panelDroit.add(champTexte, BorderLayout.NORTH);
panelDroit.add(panelImage, BorderLayout.CENTER);
fenetre.add(panelDroit, BorderLayout.CENTER);
fenetre.add(panelGauche, BorderLayout.WEST);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.pack();
fenetre.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TestInterface application = new TestInterface();
application.initAndDisplay();
}
});
}
} |
Partager