Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone



Clound SSD Virtual Server

Java Flow Layout (FlowLayout) - Example

Java Flow Layout (FlowLayout) - Example สำหรับ FlowLayout เป็นการจัดวาง Layout แบบลำดับขั้น เช่น ลำดับ 1 , 2 ,3 ,4 ในรูปแบบของ Flow แต่นอกจากนี้เรายังสามารถที่จะกลับสำดับขั้นของ Layout จากซ้ายไปขวา (LEFT_TO_RIGHT) หรือขวาไปซ้าย (RIGHT_TO_LEFT) ได้อีกด้วย

Java Flow Layout (FlowLayout)

Java Flow Layout (FlowLayout) - Example


Syntax
        FlowLayout layout = new FlowLayout();
        final JPanel panel = new JPanel();
        panel.setLayout(layout);

Component Control ของ Layout

Java Flow Layout (FlowLayout)

Example 1 การจัดวาง Layout แบบ FlowLayout

MyForm.java
package com.java.myapp;

import java.awt.EventQueue;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MyForm extends JFrame {
    
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				MyForm frame = new MyForm();
				frame.setVisible(true);
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MyForm() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 457, 173);
		setTitle("ThaiCreate.Com GUI Tutorial");
		
		FlowLayout layout = new FlowLayout();
        final JPanel panel = new JPanel();
        panel.setLayout(layout);
        
        panel.add(new JButton("Button 1"));
        panel.add(new JButton("Button 2"));
        panel.add(new JButton("Button 3"));
        panel.add(new JButton("Button 4"));
        panel.add(new JButton("Button 5"));
        panel.add(new JButton("Button 6"));
        panel.add(new JButton("Button 7"));
        panel.add(new JButton("Button 8"));
        panel.add(new JButton("Button 9"));
        
        getContentPane().add(panel);

	}
	
}

Output

Java Flow Layout (FlowLayout)

ตัวอย่างการจัดส่ง Layout แบบ FlowLayout


Example 2 การจัดวาง Layout แบบ FlowLayout และสามารถสลับลำดับของ Layout (ซ้ายไปขวา และ ขวาไปซ้าย)

MyForm.java
package com.java.myapp;

import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class MyForm extends JFrame {
    
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				MyForm frame = new MyForm();
				frame.setVisible(true);
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MyForm() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 457, 173);
		setTitle("ThaiCreate.Com GUI Tutorial");
		
		FlowLayout flowlyt = new FlowLayout();
        final JPanel panel = new JPanel();
        panel.setLayout(flowlyt);
        
        flowlyt.setAlignment(FlowLayout.TRAILING);
        JPanel controls = new JPanel();
        controls.setLayout(new FlowLayout());
        
        
        panel.add(new JButton("Button 1"));
        panel.add(new JButton("Button 2"));
        panel.add(new JButton("Button 3"));
        panel.add(new JButton("Button 4"));
        panel.add(new JButton("Button 5"));
        
       
     
        // Left to Right
        JButton btnLeftToRight = new JButton("Left to Right");
        btnLeftToRight.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent arg0) {
        		panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
        		panel.validate();
        		panel.repaint();
        	}
        });
        controls.add(btnLeftToRight);
        
        // Right to Left
        JButton btnRightToLeft = new JButton("Right to Left");
        btnRightToLeft.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent arg0) {
        		panel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        		panel.validate();
        		panel.repaint();
        	}
        });
        controls.add(btnRightToLeft);
        
        getContentPane().add(panel, BorderLayout.CENTER);
        getContentPane().add(controls, BorderLayout.SOUTH); ;


	}
	
}

Output

Java Flow Layout (FlowLayout)

แสดง Layout

Java Flow Layout (FlowLayout)

สามารถคลิกเพื่อสลับจากซ่ายไปขวา หรือ ขวาไปซ่าย






   
Share

Property & Method (Others Related)

Java GUI Layout
Java Absolute Layout (AbsoluteLayout) - Example
Java Boder Layout (BorderLayout) - Example
Java Box Layout (BoxLayout) - Example
Java Card Layout (CardLayout) - Example
Java Grid Layout (GridLayout) - Example
Java Grid Bag Layout (GridBagLayout) - Example
Java Form Layout (FormLayout) - Example
Java Mid Layout (MidLayout) - Example
Java Spring Layout (SpringLayout) - Example
Java Group Layout (GroupLayout) - Example

ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2013-08-18 13:16:03 / 2013-09-03 13:36:11
  Download : No files
 Sponsored Links / Related

 
Java GUI Layout
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่