Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement the Box layout Manager of Java Swing Class

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today Xiaobian to share with you how to achieve the Java Swing class box layout manager of the relevant knowledge, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you will learn something after reading this article, let's take a look at it.

Box layout Manager

The BoxLayout box layout manager is often used in conjunction with Box containers, while the Box class has the following two static methods:

CreateHorizontalBox () Horizontal means horizontal, that is, BoxLayout places components horizontally from left to right.

CreateVerticalBox () Vertical means vertical, which means that BoxLayout places the components vertically from top to bottom.

In addition, Box provides static methods for determining the spacing between components

Complete code: import javax.swing.*;import java.awt.*;public class demo03 {public static void main (String [] args) {JFrame jf=new JFrame ("BoxLayout example"); Box b1=Box.createHorizontalBox (); / create horizontal container Box b2=Box.createVerticalBox (); / / create horizontal container jf.add (b1) / / add the outer horizontal container to the form b1.add (Box.createVerticalStrut); / / add the vertical frame b1.add (new JButton ("west")); b1.add (Box.createHorizontalStrut (140)); / / add the horizontal frame b1.add (new JButton ("east")); b1.add (Box.createHorizontalGlue ()) / / add horizontal glue b1.add (b2); / / add nested vertical container / / add fixed area b2.add (Box.createRigidArea (new Dimension (100j) 20)); b2.add (new JButton ("north")); / / add button 3 b2.add (Box.createVerticalGlue ()) / / add vertical component b2.add (new JButton ("south")); / / add button 4 b2.add (Box.createVerticalStrut (40)); / / add 40-long vertical frame / / set window closing action, title, size position, visibility and other jf.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); jf.setBounds (100100400200); jf.setVisible (true) }} these are all the contents of this article entitled "how to implement the Box layout Manager of the Java Swing Class". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report