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 Tool Bar (JToolBar) - Swing Example

Java Tool Bar (JToolBar) - Swing Example สำหรับ JToolBar (javax.swing.JToolBar) จัดอยู่ในกลุ่มของ Container ใช้สำหรับสร้าง Toolbar หรือเครื่องมือในหน้าจอ GUI เช่น ปุ่ม Open , Save ,Cut ซึ่งเราจะคุ้นเคยดีถ้าใช้โปรแกรมบน Windows ต่าง ๆ

Java Tool Bar (JToolBar)

Java Tool Bar (JToolBar) - Swing Example


Syntax
		JToolBar toolBar = new JToolBar("My Toolbar", JToolBar.HORIZONTAL);
		
		JButton leftBtn = new JButton(new ImageIcon(getClass().getResource("left.gif")));
		leftBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null,
					    "Left Commmand",
					    "Title",
					    JOptionPane.WARNING_MESSAGE);
			}
		});
		toolBar.add(leftBtn);

Containers Icon Tools

Java Tool Bar (JToolBar)

Icon Tools บน GUI Tools

Java Tool Bar (JToolBar)

ในตัวอย่างนี้จะใช้ icons ของรูปมาแสดงใน Tool Bar

Example

MyForm.java
package com.java.myapp;

import java.awt.EventQueue;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

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, 431, 246);
		setTitle("ThaiCreate.Com Java GUI Tutorial");

		JToolBar toolBar = new JToolBar("My Toolbar", JToolBar.HORIZONTAL);
		
		// Left
		JButton leftBtn = new JButton(new ImageIcon(getClass().getResource("left.gif")));
		leftBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null,
					    "Left Commmand",
					    "Title",
					    JOptionPane.WARNING_MESSAGE);
			}
		});
		toolBar.add(leftBtn);
		
		// Right
		JButton rightBtn = new JButton(new ImageIcon(getClass().getResource("right.gif")));
		rightBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null,
					    "Right Commmand",
					    "Title",
					    JOptionPane.WARNING_MESSAGE);	
			}
		});
		toolBar.add(rightBtn);
		
		// Open
		JButton openBtn = new JButton(new ImageIcon(getClass().getResource("open.gif")));
		openBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null,
					    "Open Commmand",
					    "Title",
					    JOptionPane.WARNING_MESSAGE);	
			}
		});
		toolBar.add(openBtn);
		
		// Save
		JButton saveBtn = new JButton(new ImageIcon(getClass().getResource("save.gif")));
		saveBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null,
					    "Save Commmand",
					    "Title",
					    JOptionPane.WARNING_MESSAGE);	
			}
		});
		toolBar.add(saveBtn);
		
		getContentPane().add(toolBar, BorderLayout.NORTH);
	
	}
}

Output

Java Tool Bar (JToolBar)

แสดง Tool Bar

Java Tool Bar (JToolBar)

แต่ล่ะ Tool Bar สามารถแทรกคำสั่งให้ทำงานได้

Java Tool Bar (JToolBar)

สามารถลากออกมาเป็น Dialog ได้






   
Share

Property & Method (Others Related)

Java GUI Swing Containers
Java Panel (JPanel) - Swing Example
Java Tabbed Pane (JTabbedPane) - Swing Example
Java Split Pane (JSplitPane) - Swing Example
Java Scroll Pane (JScrollPane) - Swing Example
Java Desktop Pane (JDesktopPane) - Swing Example
Java Internal Frame (JInternalFrame) - Swing Example
Java Layered Pane (JLayeredPane) - Swing Example

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


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


   


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

 
Java GUI Swing Containers
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 01
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 อัตราราคา คลิกที่นี่