In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use the type of swing layout manager, which is very detailed and has a certain reference value. Friends who are interested must finish it!
When using Swing to add components to a container, you need to consider the location and size of the components. If you do not use the layout manager, you need to draw the location of each component on the paper and calculate the distance between the components before adding it to the container. Although it can flexibly control the location of the component, it is very troublesome to implement.
Swing layout Manager Type
To speed up development, Java provides layout managers that manage components uniformly so that developers do not have to worry about whether components overlap or not. This section describes the six layout types provided by Swing, all of which implement the LayoutManager interface.
Border layout Manager
BorderLayout (Border layout Manager) is the default layout manager for Window, JFrame, and JDialog. The border layout manager divides the window into five areas: North, South, East, West, and Center. Among them, North means north and will occupy the top of the panel; Soufe means south and will occupy the lower part of the panel; East means east and will occupy the right side of the panel; West means west and will occupy the left side of the panel; and the middle area Center is the remaining area after the east, south, west and north are filled, as shown in figure 1.
Schematic diagram of border layout manager area partition
Tip: the border layout manager does not require all areas to have components. If there are no components in the surrounding areas (North, South, East, and West areas), the Center area will supplement them. If more than one component is added to a single area, the component that is added later will overwrite the original component, so only the last component added is displayed in the area.
The construction method of the BorderLayout layout manager is as follows.
BorderLayout (): create a Border layout with no gaps between components.
BorderLayout (inthgap,intvgap): create a Border layout where hgap represents the horizontal interval between components and vgap represents the vertical interval between components in pixels.
Swing layout case
Use BorderLayout to split the window into five areas and add a label button to each area. The implementation code is as follows:
Plain text copy
Packagech27
Importjavax.swing.JButton
Importjavax.swing.JFrame
Importjavax.swing.JLabel
Importjavax.swing.JPanel
Importjava.awt.*
PublicclassBorderLayoutDemo
{
Publicstaticvoidmain (String [] agrs)
The above is all the content of the article "how to use swing layout Manager types". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.