setSize() method is used to set the size for the frame and the set visibility() method is being used to set the visibility of the frame. The size and visibility are again determined separately for the JFrame. Our code has created five regions with gaps between them using vgap and hgap parameters in BorderLayout( ). You can see in the screenshot below (after the code). The following program creates components in a JFrame whose instance class is ‘border’ in a similar way as above but with vertical and horizontal gaps. When the code runs, the following output is displayed.īorderLayout (int hgap, int vgap) is also written as BorderLayout (int, int) is used to create a border layout with the given horizontal (hgap) and vertical (vgap) gaps or spaces between the following is an example code using BorderLayout (int, int) constructor. In the below screenshot, you can see how the code looks like in the text editor. Function to set visible status of the frame In the center, will be the button named 'Center' Lying at right, will be the button named 'West' Lying at left, will be the button named 'East' Lying at bottom, will be the button named 'South' Lying at top, will be the button named 'North' setSize() method is used to set the size for the frame and the set visibility() method is being used to set the visibility of the frame.Ĭode //Java Program illustrating the BorderLayout The size and visibility are determined separately for the JFrame. Our code has created five regions using five JButton and then these are added to the layout or JFrame using an add() method. You can see in the screenshot below (after the code), there are five regions. ![]() The following program creates components in a JFrame whose instance class is ‘border’. Following is an example code using the BorderLayout() constructor. We will discuss them one by one along with their examples.īorderLayout Class is used to create a border layout but without gaps between the components. The border layout constructors are discussed below: The border layout constructor use gap and gap parameters to specify horizontal gaps and vertical gaps between the components. BorderLayout Constructors in JavaīorderLayout Constructors are used to creating new border layouts with gaps or with no gaps between the components. In addition to the above-listed constants, BorderLayout provides other positioning constants too such as PAGE_START, PAGE_END, etc. public static final int EAST: The East layout constant at the left of the container.public static final int WEST: The West layout constant at the right of the container.public static final int CENTER: The Center layout constant in the middle of the container.public static final int SOUTH: The South layout constant at bottom of the container.public static final int NORTH: The North layout constant at top of the container. ![]() Constants for each region used in our code are listed below: We use these constants while adding a component using a border layout. The regions discussed here identified by a corresponding constant named NORTH, SOUTH, EAST, WEST, and the constant for the middle region as CENTER. The border layout provides a collection of constants used for positioning components. ![]() Each region may contain only one component. Out of five, four regions or areas are referred to as north, south, east and west and the middle region is referred to as the center. The border layout arranges these components into five different regions. ![]() BorderLayout is used to layout a container i.e. The window objects such as JFrame, JWindow, JDialog use this class to be displayed as GUI components.
0 Comments
Leave a Reply. |