Specifying gaps Constructor or MethodīorderLayout(int horizontalGap, int verticalGap)ĭefines a border layout with specified gaps between components. The following table lists constructors and methods to specify gaps (in pixels). For example:Īdd(BorderLayout.CENTER, component) //valid but old fashionedĪdd("Center", component) //valid but error prone If this component is missing from a container controlled by a BorderLayout object, make sure that the component's location was specified and no another component was placed in the same location.Īll tutorial examples that use the BorderLayout class specify the component as the first argument to the add method. Specify the component's location (for example, BorderLayout.LINE_END) as one of the arguments to the add method. Pane.add(button, BorderLayout.LINE_START) īutton = new JButton("Long-Named Button 4 (PAGE_END)") Make the center component big, since that's theīutton = new JButton("Button 2 (CENTER)") ītPreferredSize(new Dimension(200, 100)) īutton = new JButton("Button 3 (LINE_START)") Pane.add(button, BorderLayout.PAGE_START) JButton button = new JButton("Button 1 (PAGE_START)") Container pane = aFrame.getContentPane(). These areas are specified by the BorderLayout constants: Alternatively, to compile and run the example yourself, consult the example index.Īs the preceding picture shows, a BorderLayout object has five areas. Java™ Web Start ( download JDK 7 or later). The following figure represents a snapshot of an application that uses theĬlick the Launch button to run BorderLayoutDemo using If you are interested in using JavaFX to create your GUI, see Otherwise, if you want to code by hand and do not want to use GroupLayout, then GridBagLayout is recommended as the next most flexible and powerful layout manager. If you are not interested in learning all the details of layout management, you might prefer to use the GroupLayout layout manager combined with a builder tool to lay out your GUI. Note: This lesson covers writing layout code by hand, which can be challenging.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |