Page 734 - Introduction to Programming with Java: A Problem Solving Approach
P. 734

                700 Chapter 17 GUI Programming—Component Layout, Additional GUI Components
   West’s contents determine this divider’s position.
north
East’s contents determine this divider’s position.
            west
center
east
          south
 North’s contents determine this divider’s position.
 South’s contents determine this divider’s position.
             Figure 17.4 BorderLayout regions
empty causes the east dividing line to move all the way to the right border. The south region being empty
causes the south dividing line to move all the way down to the bottom border. Here’s the resulting layout:
north
            Apago PDF Enhancer
   west
 center
What happens if the center region is empty? The center region doesn’t control any of the dividing lines, so nothing happens.
Adding Components
Suppose you have a container class that uses a BorderLayout manager. To add a component to one of the container’s BorderLayout regions, call the container’s add method like this:
add(<component>, <region>);
Replace <component> by a component (a JLabel object, a JButton object, and so on) and replace <region> by one of these named constants: BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout .WEST,BorderLayout.EAST,or BorderLayout.CENTER.Forexample,here’showtoadda Tunisia button to the north region:
add(new JButton("Tunisia"), BorderLayout.NORTH);
If you call the add method with no region argument, the center region is used by default. Thus, to add a Central African Republic button to the center region, you can use either of these two statements:











































































   732   733   734   735   736