package com.dh.ch11;

import javax.swing.*;
import java.awt.*;

public class ToolBarDemo extends JFrame {
	private JPanel p;
	// 声明工具栏
	private JToolBar toolBar;
	private JButton btnCopy, btnPost, btnCut;

	public ToolBarDemo() {
		super("工具栏");
		p = new JPanel();
		// 创建工具栏
		toolBar = new JToolBar();
		// 将工具栏对象添加到窗体的上方(北面)
		this.add(toolBar, BorderLayout.NORTH);
		// 创建按钮对象,按钮上有图片
		btnCopy = new JButton(new ImageIcon("images\\copy.jpg"));
		btnPost = new JButton(new ImageIcon("images\\paste.jpg"));
		btnCut = new JButton(new ImageIcon("images\\cut.jpg"));
		// 设置按钮的工具提示文本
		btnCopy.setToolTipText("复制");
		btnPost.setToolTipText("粘贴");
		btnCut.setToolTipText("剪切");
		// 将按钮添加到工具栏中
		toolBar.add(btnCopy);
		toolBar.add(btnPost);
		toolBar.add(btnCut);

		this.add(p);
		this.setSize(200, 150);
		this.setLocation(100, 100);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public static void main(String[] args) {
		ToolBarDemo f = new ToolBarDemo();
		f.setVisible(true);
	}
}

java像工具栏面板跳转 java工具栏怎么设计_java像工具栏面板跳转