Sitemap
CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Chapter 13

3 min readApr 23, 2022

--

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.

Press enter or click to view image in full size

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.

Press enter or click to view image in full size

BoxLayout forces a ‘newline’ to make the components wrap to the next line.

Press enter or click to view image in full size

Swing components

Press enter or click to view image in full size

JTextArea

Press enter or click to view image in full size

JCheckBox

JList

Press enter or click to view image in full size
Press enter or click to view image in full size

--

--

Written by Harshana Samarasinghe

“Truth can only be found in one place: the code.” - Associate Engineer — Java Technology at Virtusa Sri Lanka -

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers