e816. 创建工具栏
A toolbar can be either horizontal or vertical. When the orientation is horizontal, the objects in the toolbar are displayed left-to-right. When the orientation is vertical, the objects in the toolbar are displayed top-to-bottom. This orientation is automatically changed when the toolbar is moved to the top or side of a container.
// Create a horizontal toolbar
JToolBar toolbar = new JToolBar(); // Create a vertical toolbar
toolbar = new JToolBar(null, JToolBar.VERTICAL); // Get current orientation
int orient = toolbar.getOrientation();
The following code adds various buttons to the toolbar:
// Get icon
ImageIcon icon = new ImageIcon("icon.gif"); // Create an action with an icon
Action action = new AbstractAction("Button Label", icon) {
// This method is called when the button is pressed
public void actionPerformed(ActionEvent evt) {
// Perform action
}
}; // Add a button to the toolbar; remove the label and margin before adding
JButton c1 = new JButton(action);
c1.setText(null);
c1.setMargin(new Insets(0, 0, 0, 0));
toolbar.add(c1); // Add a toggle button; remove the label and margin before adding
JToggleButton c2 = new JToggleButton(action);
c2.setText(null);
c2.setMargin(new Insets(0, 0, 0, 0));
toolbar.add(c2); // Add a combobox
JComboBox c3 = new JComboBox(new String[]{"A", "B", "C"});
c3.setPrototypeDisplayValue("XXXXXXXX"); // Set a desired width
c3.setMaximumSize(c3.getMinimumSize());
toolbar.add(c3);
// See also e765 监听组合框中选择不同的项
If the toolbar is to be floatable (see e818 防止工具栏可移动), it must be added to a container with a BorderLayout.
// Add the toolbar to a frame
JFrame frame = new JFrame();
frame.getContentPane().add(toolbar, BorderLayout.NORTH);
frame.pack();
frame.setVisible(true);
| Related Examples |
e816. 创建工具栏的更多相关文章
- 用CToolBarCtrl类为对话框创建工具栏
---恢复内容开始--- 首先CToolBarCtrl类内部维护了三个重要的数据结构:一个图像列表,一个字符串列表,一个TBBUTTON结构体的列表. 知道了这一点,下面的理解起来就轻松了.慢慢来: ...
- wxpython 创建工具栏和菜单栏
下面看一下关于创建工具栏,状态栏和菜单的方法,看下面一个例子: import wx class ToolBarFrame(wx.Frame): def __init__(self,parent,id) ...
- win32创建工具栏的自定义图标
注意点:使用LoadImage函数加载bmp图片,这里特指BMP图片,其实LoadImage可以加载很多格式的图片 HBITMAP bitmap = (HBITMAP)LoadImage((HINST ...
- Android 学习笔记四:创建工具栏按钮
原文:http://blog.csdn.net/lihongxun945/article/details/48951199 前面我们已经可以在一个Activity中添加一些按钮之类的组件.由于手机的屏 ...
- 雷林鹏分享:jQuery EasyUI 数据网格 - 创建复杂工具栏
jQuery EasyUI 数据网格 - 创建复杂工具栏 数据网格(datagrid)的工具栏(toolbar)可以包含按钮及其他组件. 您可以通个一个已存在的 DIV 标签来简单地定义工具栏布局,该 ...
- MFC工具栏的创建、设计与使用实例
本文通过实例说明MFC工具栏的创建.设计和使用方法,包括三个demo. demo1:创建一个工具栏 C++代码 //摘抄自MSDN demo1 (创建一个工具栏) 1.Create a t ...
- VS2010/MFC编程入门之三十七(工具栏:工具栏的创建、停靠与使用)
鸡啄米在上一节教程中讲了工具栏资源及CToolBar类,本节继续讲解工具栏的相关知识,主要内容包括工具栏的创建.停靠与使用. 工具栏的使用 上一节中鸡啄米提到过,一般情况下工具栏中的按钮在菜单栏中都有 ...
- VS2010-MFC(工具栏:工具栏的创建、停靠与使用)
转自:http://www.jizhuomi.com/software/217.html 上一节教程讲了工具栏资源及CToolBar类,本节继续讲解工具栏的相关知识,主要内容包括工具栏的创建.停靠与使 ...
- 【Windows编程】系列第六篇:创建Toolbar与Statusbar
上一篇我们学习了解了如何使用Windows GDI画图,该应用程序都是光光的静态窗口,我们使用Windows应用程序,但凡稍微复杂一点的程序都会有工具栏和状态栏,工具栏主要用于一些快捷功能按钮.比如典 ...
随机推荐
- 每日英语:How Often Do Gamblers Really Win?
The casino billboards lining America's roadways tantalize with the lure of riches. 'Easy Street. It' ...
- ubuntu 安装 sublime
1.安装包下载 http://www.sublimetext.com/ 2.解压并移动到/usr/lib/下 tar -xvf Sublime.tar.bz2 mv Sublime /usr/lib/ ...
- 腾讯云CentOS 安装 Hadoop 2.7.3
1.安装 jdk yum install java 2.安装maven wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.5.0/binar ...
- C语言 · LOG大侠
标题:LOG大侠 atm参加了速算训练班,经过刻苦修炼,对以2为底的对数算得飞快,人称Log大侠. 一天,Log大侠的好友 drd 有一些整数序列需要变换,Log大侠正好施展法力... 变换的规则是: ...
- C语言 · 字符串编辑
算法训练 字符串编辑 时间限制:1.0s 内存限制:512.0MB 问题描述 从键盘输入一个字符串(长度<=40个字符),并以字符 ’.’ 结束.编辑功能有: 1 D:删除一个 ...
- 关于OpenVR
一直在期待一种大一统的开放的VR技术规范,虽然短期内这点明显是不太现实的.前几天在翻译Godot的开发进展#6那篇文章时,看到了一个词OpenVR,瞬间有感觉了. 从我的经历的技术规范演进版本来看,从 ...
- C++客户端访问Java服务端发布的SOAP模式的WebService接口
gSOAP是一个绑定SOAP/XML到C/C++语言的工具,使用它可以 简单快速地开发出SOAP/XML的服务器端和客户端 Step1 使用gsoap-2.8\gsoap\bin\win32\wsdl ...
- led子系统
最简单的led驱动就是从端口输出0或1来关闭或点亮灯.而我们这里讲的led子系统,主要是对led事件进行了分装和优化,这里我们主要讲的是可 以实现跨平台的led驱动.不管你是使用三星的平台,还是Atm ...
- TCP/IP协议栈
TCP/IP协议栈包含TCP层.IP层.链路层.NIC驱动等. 参考: 1. 全面了解linux TCP/IP协议栈 2. 跟我学TCP/IP系列
- CPP基础
CPP基础1. 如果没有指明访问限定符(public,private),class中默认的private,而struct中的成员默认是public的. #include <iostream> ...