Java common components and layout manager

Source: Internet
Author: User

Swing components are grouped by function and can be divided into the following categories:

? Top-level containers: JFrame, JApplet, JDialog and JWindow

? Intermediate containers: JPanel, JScrollPane, JSplitPane, JToolBar

? Special containers: intermediate containers that have special effects on the user interface, such as: JInternalFrame, JRootPane, JLayeredPane, and Jdestoppane

? Basic components: JButton, JComboBox, JList, JMenu, JSlider

? Display component of non-editable information: A component that displays non-editable information to the user, such as: JLabel, JProgressBar, JToolTip, etc.

? Components for editable information: JTable, JTextArea, and JTextField

? Special dialog box components: JColorChooser and JFileChooser

Layout Manager is used to manage the layout of components in containers

All containers have a default layout manager, and if no layout manager is specified for the container, the default layout manager is used

Specify the layout manager for the container by calling SetLayout (new xxxlayout), such as:

C. setlayout (New Xxxlayout)

Common layout managers:

1. FlowLayout, the component moves in a direction like the flow of water, JPanel uses the FlowLayout layout Manager by default (does not limit the component size, the container scale component size is unchanged, but the position changes)

2. BorderLayout, divide the container into south, north, left, right, and five parts, if you can use Borderlayout.south to set the position of the component

3. GridLayout, Grid Layout, constructed as follows: gridelayout (int rows,int cols), gridelayout (int rows,int cols,int hgap,int vgap), when the container to the layout manager When adding components, the default is from left to right, from top to bottom in each grid (the relative position of the component does not change with the container scaling, but the size changes, all components are the same size)

4. CardLayout layout Manager, treat all components that join the container as a stack of cards

5. GridBagLayout, powerful, but very complex

6. BoxLayout, retains many of the advantages of gridbaglayout, but not so complicated

Java common components and layout manager

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.