Cet article décrit l'utilisation d'un gestionnaire de mise en page pour la programmation Java. Partagez-le pour votre référence, comme suit:
Jetons un coup d'œil à l'effet de course:
Le code complet est le suivant:
Package awtdemo; import java.awt.borderlayout; import java.awt.contitainer; import javax.swing.box; import javax.swing.jbutton; import javax.swing.jframe; javax.swing.jtextfield; / ** * Utilisation du gestionnaire de mise en page de la boîte * * @author han * * / public class boxlayout_1 étend jframe {/ ** * * / private statique final long serialversionuid = 689692555596855002l; public boxlayout_1 () {// TODO CONTRUTER STUB CONTUTER CONTRUTTEUR AUTO AUTO = GetContentPane (); Box Box = Box.CreateVectalBox (); contener.add (box, borderlayout.north); box.Add (box.CreateverticalStrut (5)); Box topicBox = box.CreateHorizontalBox (); box.add (topicbox); topicbox.setAlignmentX (1); topicbox.add (box.CreateHorizontalStrut (5)); JLABEL TUOCHLABEL = NOUVEAU JLABEL ("Tubject:"); topicbox.add (topicLabel); topicbox.add (box.CreateHorizontalStrut (5)); JTextfield topicTextField = new JTextfield (30); topicbox.add (topicTextField); Box Box2 = Box.CreateVerticalBox (); contener.add (box2, borderlayout.center); Box ContentBox = Box.CreateHorizontalBox (); ContentBox.SetAlignmentX (1); Box2.Add (Box.CreateVerticalStrut (5)); box2.add (contenubox); ContentBox.Add (Box.CreateHorizontalStrut (5)); JLabel contentLabel = new JLabel ("Content:"); ContentLabel.SetAlignmenty (0); contentbox.add (contenuLabel); ContentBox.Add (Box.CreateHorizontalStrut (5)); StringBuilder StringBuilder = new StringBuilder (); String ContentsTring = new String ("Utilisez le gestionnaire de mise en page de la boîte pour obtenir l'alignement droit des composants" + "et l'alignement supérieur, et contrôler l'espacement entre les composants!"); StringBuilder.APPEND (ContentString); StringBuilder.APPEND (ContentString); StringBuilder.APPEND (ContentString); ContentString = StringBuilder.ToString (); JTextArea contentTextArea = new JTextArea (ContentsTring, 3, 30); contentTextArea.setlinewrap (true); Jscrollpane scrollPane = new JScrollPane (); ScrollPane.Setalignmenty (0); ScrollPane.SetViewportView (contentTextArea); Contentbox.add (ScrollPane); ContentBox.Add (Box.CreateHorizontalStrut (5)); // System.out.println (contentTextArea.RequestFocusInWindow ()); Box2.Add (Box.CreateVerticalStrut (5)); JBUTTON SoumidButton = new JBUTTON ("OK"); Box2.Add (soumisButton); soumitButton.setalignmentX (1); Box2.Add (Box.CreateVerticalStrut (5)); } / ** * @param args * / public static void main (String [] args) {// TODO Méthode générée automatique Stub boxlayout_1 frame = new BoxLayout_1 (); frame.setTitle ("www.vevb.com - Utilisation du gestionnaire de mise en page"); frame.setVisible (true); frame.setDefaultCloseOperation (jframe.exit_on_close); frame.pack (); }}Pour plus d'informations sur les algorithmes Java, les lecteurs qui sont intéressés par ce site peuvent afficher les sujets: "Structure de données Java et tutoriel d'algorithme", "Résumé des conseils de nœud de Dom Operation Java", "Résumé du fichier Java et des conseils d'opération de répertoire" et "Résumé des conseils d'opération Java Cache"
J'espère que cet article sera utile à la programmation Java de tous.