Chapter 13
Using Swing
A swing component is a widget. Components that extend from javax.swing.Jcomponent include text fields, buttons, scrollable lists, and radio buttons.
The components contained within the component with which the layout manager is linked are controlled by the layout manager. The frame’s layout manager controls the panel’s size and positioning.
How does the layout manager decide?
A layout scenario:
Let’s add a button to the east region:
Divide the background into five parts using the border layout. Each area can have one component. Components in the north and south are given preference for height rather than width. Components in the east and west are prioritized for width rather than height. Whatever is left goes to the component in the middle. Divide the backdrop into five parts using the border layout. Each area can have one component. Components in the north and south are given preference for height rather than width. Components in the east and west are prioritized for width rather than height. Whatever is left goes to the component in the middle. Divide the background into five parts using the border layout. Each area can have one component. Components in the north and south are given preference for height rather than width. Components in the east and west are prioritized for width rather than height. Whatever is left goes to the component in the middle. Divide the backdrop into five parts using the border layout. Each area can have one component. Components in the north and south are given preference for height rather than width. Components in the east and west are prioritized for width rather than height. Whatever is left goes to the component in the middle.
Flow layout: arrange components from left to right, top to bottom, in the order in which they were introduced. If the components don’t fit horizontally, wrap them into a new line.
Get Harshana Samarasinghe’s stories in your inbox
Join Medium for free to get updates from this writer.
Box layout: Components may be stacked vertically using a box layout. You may use this to create a kind of component return key, forcing components to start a new line. You may force a component to be in a new line even if there is space.
BoxLayout forces a ‘newline’ to make the components wrap to the next line.
Swing components









