New to JavaProgramming Center
Java Platform Overview |
Getting Started |
Step-by-Step Programming
![]()
Contents Which is step 2? Setting a layout manager in the constructor is the second step in the creating the However, a layout manager for each class is necessary.
Layout ManagersBefore building and adding components to a container, it's good to have some idea of how you want those components arranged. Real world objects, like the furniture in your home, are arranged and set in specific locations, according to which objects need to be close to one another and which objects can be spaced farther apart. For instance, it might not make sense to put your couch beside your television, but it would make sense to set the couch in front of the television with some space between the two objects.
Application objects also need to be arranged. Layout managers are special objects that position the objects
you create and add to containers. Each container, such as The Swing tool set primarily consists of the layout classes provided by the Abstract Window Toolkit (AWT), which has five layout manager classes:
In addition, Swing has several layout managers, such as the box, scroll pane, overlay, and viewport layouts. Deciding which manager to use depends on how you want to arrange the components within a container. The simplest layout manager is flow layout because it arranges components from left to right. There are limited uses for this layout. If you have only one or two components in your application, then flow layout might be sufficient. Border Layout ManagerThe border layout manager is an easy-to-use layout manager. It is popular because you can do so much or so little with it. Five components may be added to the border layout manager and arranged on any of the four borders and in the center. This pattern is similar to geographical locations indicated by North, South, East, West, and Center in the image below:
If the application is resized, the components are resized accordingly, and the arrangement is preserved and maintained by the layout manager. Each region is stretched to fill the container. Notice how North and South regions extend to the left and right edges. Also note that the West, Center, and East areas do not extend to the upper and lower edges.
Only five components may be added to the border layout, one in each region. You can overcome this limitation by adding another container, such as a Contrary to placing layouts within layouts, you don't have to make use of all five regions of the border layout manager.
Like the illustration above, the
To start, you need to set up the class constructor, and call the method to use the border
layout manager for this
The At this point, you are ready to create the components that are later added to the panel and arranged by the layout manager.
You declared three variables at the beginning of the
| ||||||||
|
| ||||||||||||