Java Swing stream layout manager

Source: Internet
Author: User

/*** Java stream Layout * @ author gao */package com. gao; import java. awt. flowLayout; import javax. swing. JButton; import javax. swing. JFrame; import javax. swing. JPanel; import javax. swing. border. emptyBorder; @ resolve ("serial") public class FlowLayoutDemo extends JFrame {private JPanel contentPane; private JButton button1; private JButton button2; private JButton button3; private JButton button4; private JButton button5; private JButton button6; private JButton button7; private JButton button8; private JButton button9; public FlowLayoutDemo () {this. contentPane = new JPanel (); // create the content panel this. contentPane. setBorder (new EmptyBorder (5, 5, 5); // you can specify the border of the Panel. setContentPane (contentPane); // The application content panel this. contentPane. setLayout (new FlowLayout (FlowLayout. CENTER, 5, 5); // set the layout manager of the content panel to streaming layout this. button1 = new JButton ("button 1"); // create the button this. button2 = new JButton ("button 2"); this. button3 = new JButton ("button 3"); this. button4 = new JButton ("button 4"); this. button5 = new JButton ("button 5"); this. button6 = new JButton ("button 6"); this. button7 = new JButton ("button 7"); this. button8 = new JButton ("button 8"); this. button9 = new JButton ("button 9"); this. contentPane. add (button1); // add the button this on the panel. contentPane. add (button2); this. contentPane. add (button3); this. contentPane. add (button4); this. contentPane. add (button5); this. contentPane. add (button6); this. contentPane. add (button7); this. contentPane. add (button8); this. contentPane. add (button9); this. setTitle ("stream layout"); // set the Form title this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); // sets this when the form exits. setBounds (100,100,300,150); // you can specify the position and size of the form. setVisible (true); // set the form to be visible} public static void main (String [] args) {FlowLayoutDemo example = new FlowLayoutDemo ();}}

The stream layout manager is the default layout management of the Panel. It arranges controls from left to right or from right to left, which is very similar to text lines in paragraphs. The stream direction depends on the componentOrientation attribute;

Demo running result:


When the form is stretched, the button position changes. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140502/20140502092307134.jpg" alt = "">


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.