Partage
  • Partager sur Facebook
  • Partager sur Twitter

BoxLayout, panel, et alignement

désactiver le "centrage automatique"

    25 avril 2010 à 23:03:45

    Bonsoir,
    voici mon problème :
    j'ai mon IHM, j'ai un BoxLayout vertical qui contient mes 8 panels dans lesquelles je met d'autre BoxLayout soit horizontal soit vertical...
    Mais impossible de placer mes composants à gauche !
    Voici mon code :
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    
    import javax.swing.BorderFactory;
    import javax.swing.Box;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    
    
    public class MaFenetre {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		
    		Dimension tailleEcran = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    		int hauteur = (int)tailleEcran.getHeight();
    
    		// TODO Auto-generated method stub
    		JFrame mafenetre = new JFrame();
    		mafenetre.setTitle("Plateforme de suivi au sol d'expériences embarquées dans des ballons et des fusées"); 
    		mafenetre.setSize(500,hauteur-50); 
    		mafenetre.setLocationRelativeTo(null); 
    		mafenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		JPanel pan1 = new JPanel();
    		JPanel pan2 = new JPanel();
    		JPanel pan3 = new JPanel();
    		JPanel pan4 = new JPanel();
    		JPanel pan5 = new JPanel();
    		JPanel pan6 = new JPanel();
    		JPanel pan7 = new JPanel();
    		JPanel pan8 = new JPanel();
    		
    		
    		pan1.setBorder(BorderFactory.createTitledBorder("Nom de l'expérience"));
    		pan2.setBorder(BorderFactory.createTitledBorder("Type d'expérience"));
    		pan3.setBorder(BorderFactory.createTitledBorder("Nom de l'établissement"));
    		pan4.setBorder(BorderFactory.createTitledBorder("Niveau de satisfaction"));
    		pan5.setBorder(BorderFactory.createTitledBorder("Vos coordonnées"));
    		pan6.setBorder(BorderFactory.createTitledBorder("Remarques éventuelles (bugs, amélioration souhaitées, etc...)"));
    		pan7.setBorder(BorderFactory.createTitledBorder("Envoyer les résultats"));
    		pan8.setBorder(BorderFactory.createTitledBorder("Date et heure de lancement"));
    		
    		//pan1.setAlignmentX(Component.LEFT_ALIGNMENT);
    		
    		/*mafenetre.add(pan1);
    		mafenetre.add(pan2);
    		mafenetre.add(pan3);
    		mafenetre.add(pan4);
    		mafenetre.add(pan5);
    		mafenetre.add(pan6);
    		mafenetre.add(pan7);*/
    
    		/*mafenetre.setLayout(new GridLayout(7,1));
            
            mafenetre.getContentPane().add(pan1);
            mafenetre.getContentPane().add(pan2);
            mafenetre.getContentPane().add(pan3);
            mafenetre.getContentPane().add(pan4);
            mafenetre.getContentPane().add(pan5);
            mafenetre.getContentPane().add(pan6);
            mafenetre.getContentPane().add(pan7);*/
    		
    		Box hbox1 = Box.createVerticalBox();
    		hbox1.setAlignmentX(Component.LEFT_ALIGNMENT);
    		mafenetre.add(hbox1);
    		
    		hbox1.add(pan1);
    		hbox1.add(pan2);
    		hbox1.add(pan3);
    		hbox1.add(pan8);
    		hbox1.add(pan4);
    		hbox1.add(pan5);
    		hbox1.add(pan6);
    		hbox1.add(pan7);
    		 
            // Dans le panneau 1
    		Box hbox2 = Box.createHorizontalBox();
    		hbox2.setAlignmentX(Component.LEFT_ALIGNMENT);
            JTextField txt1 = new JTextField("experience_date_heure");
            pan1.add(hbox2);
            hbox2.add(txt1);
            
            // Dans le panneau 2
            Box hbox6 = Box.createVerticalBox();
            hbox6.setAlignmentX(Component.LEFT_ALIGNMENT);
            
            JRadioButton radio4 = new JRadioButton("Ballon");
            JRadioButton radio5 = new JRadioButton("Fusée expérimentale");
            JRadioButton radio6 = new JRadioButton("Minifusée");
            JRadioButton radio7 = new JRadioButton("Autre");
            
            //JTextField txt2 = new JTextField("Précisez ici");
            pan2.add(hbox6);
            hbox6.add(radio4);
            hbox6.add(radio5);
            hbox6.add(radio6);
            hbox6.add(radio7);
            
            // Dans le panneau 3
            Box hbox7 = Box.createHorizontalBox();
            
            pan3.add(hbox7);
            
            JTextField txt9 = new JTextField(10);
            String[] etab = {"Club", "Ecole primaire", "Collège", "Lycée", "Université", "Autre"};
            JComboBox combo1 = new JComboBox(etab);
            hbox7.add(combo1);
            hbox7.add(txt9);
            
            // Dans le panneau 8
            Box hbox10 = Box.createHorizontalBox();
            
            pan8.add(hbox10);
            
            String[] jour = {"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"};
            String[] mois = {"Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre" , "Novembre", "Décembre"};
            String[] annee = {"2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020"};
            String[] heure = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "00"};
            String[] minutes = {"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"};
            
            JLabel lab8 = new JLabel("Le ");
            JLabel lab9 = new JLabel(" à ");
            JLabel lab10 = new JLabel(" heures ");
            JLabel lab11 = new JLabel(" minutes ");
            
            JComboBox combo2 = new JComboBox(jour);
            JComboBox combo3 = new JComboBox(mois);
            JComboBox combo4 = new JComboBox(annee);
            JComboBox combo5 = new JComboBox(heure);
            JComboBox combo6 = new JComboBox(minutes);
            
            hbox10.add(lab8);
            hbox10.add(combo2);
            hbox10.add(combo3);
            hbox10.add(combo4);
            hbox10.add(lab9);
            hbox10.add(combo5);
            hbox10.add(lab10);
            hbox10.add(combo6);
            hbox10.add(lab11);
            
            
            
            // Dans le panneau 4
            Box hbox3 = Box.createVerticalBox();
            
            JRadioButton radio1 = new JRadioButton("Pas satisfait");
            JRadioButton radio2 = new JRadioButton("Satisfait");
            JRadioButton radio3 = new JRadioButton("Très satisfait");
            
            pan4.add(hbox3);
            
            hbox3.add(radio1);
            hbox3.add(radio2);
            hbox3.add(radio3);
            
            // Dans le panneau 5
            Box hbox4 = Box.createVerticalBox();
            
            JTextField txt2 = new JTextField(10);
            JTextField txt3 = new JTextField(10);
            JTextField txt4 = new JTextField(10);
            JTextField txt5 = new JTextField(5);
            JTextField txt6 = new JTextField(7);
            JTextField txt7 = new JTextField(10);
            JTextField txt8 = new JTextField(10);
            
            JLabel lab1 = new JLabel("Nom");
            JLabel lab2 = new JLabel("Prénom");
            JLabel lab3 = new JLabel("Adresse");
            JLabel lab4 = new JLabel("Code postal");
            JLabel lab5 = new JLabel("Ville");
            JLabel lab6 = new JLabel("Téléphone");
            JLabel lab7 = new JLabel("Email");
            
            pan5.add(hbox4);
                
            hbox4.add(lab1);
            hbox4.add(txt2);
            hbox4.add(lab2);
            hbox4.add(txt3);
            hbox4.add(lab3);
            hbox4.add(txt4);
            hbox4.add(lab4);
            hbox4.add(txt5);
            hbox4.add(lab5);
            hbox4.add(txt6);
            hbox4.add(lab6);
            hbox4.add(txt7);
            hbox4.add(lab7);
            hbox4.add(txt8);
            
            // Dans le panneau 6
            JTextArea area1 = new JTextArea();
            pan6.setLayout(new BorderLayout());
            pan6.add(area1, BorderLayout.CENTER);
            
            // Dans le panneau 7
            JButton button1 = new JButton("Envoyer !");
            //pan7.setLayout(new BorderLayout());
            Box hbox5 = Box.createHorizontalBox();
            pan7.add(hbox5);
            hbox5.setAlignmentX(Component.LEFT_ALIGNMENT);
            hbox5.add(button1);
            //pan7.add(button1, BorderLayout.CENTER);
            
            mafenetre.setVisible(true);
    
    	}
    
    }
    

    Image utilisateur



    • Partager sur Facebook
    • Partager sur Twitter
      2 mai 2010 à 16:43:00

      Re-bonjour,
      je me permet un petit up si quelqu'un à une idée,
      merci
      • Partager sur Facebook
      • Partager sur Twitter

      BoxLayout, panel, et alignement

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown