Java SWT Ribbon的使用

关于Java Swing的Ribbon的使用可以见:Java Swing Ribbon(Flamingo)的使用

下面这篇文章主要介绍Java SWT界面编写过程中Ribbon的使用。与Swing相同,SWT开发时也有一套开发包可以实现Ribbon样式。


1 软件包下载

Java SWT开发过程中用到的Ribbon开发包下载地址为:SWT_Ribbon开发包

主要包含3个文件:



2 代码实现

下面编写一个简单代码实现Java SWT Ribbon功能。

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import com.hexapixel.widgets.generic.ImageCache;
import com.hexapixel.widgets.ribbon.RibbonButton;
import com.hexapixel.widgets.ribbon.RibbonButtonGroup;
import com.hexapixel.widgets.ribbon.RibbonCheckbox;
import com.hexapixel.widgets.ribbon.RibbonGroup;
import com.hexapixel.widgets.ribbon.RibbonShell;
import com.hexapixel.widgets.ribbon.RibbonTab;
import com.hexapixel.widgets.ribbon.RibbonTabFolder;
import com.hexapixel.widgets.ribbon.RibbonTooltip;

public class AbstractButtonPainter {

	public static void main(String[] args) {
		Display display = Display.getDefault();
		// Ribbon 组件官方网址 http://hexapixel.com/projects/ribbon
		final RibbonShell shell = new RibbonShell(display);
		shell.setText("SWT Ribbon Demo");

		RibbonTabFolder folder = shell.getRibbonTabFolder();
		RibbonTab tab1 = new RibbonTab(folder, "snakedj.ch - swiss java blog");
		RibbonTab tab2 = new RibbonTab(folder, "jugr.ch - Java User Group Graubünden");
		folder.pack();

		RibbonTooltip toolTip = new RibbonTooltip(
				"RibbonTooltip",
				"This is a RibbonTooltip content text",
				ImageCache.getImage("tooltip.jpg"),
                                ImageCache.getImage("questionmark.gif"), "Press F1 for more help");
		RibbonGroup group1 = new RibbonGroup(tab1, "Java", toolTip);
		new RibbonButton(group1, ImageCache.getImage("olb_picture4.gif"), 
                                "J2SE", RibbonButton.STYLE_ARROW_DOWN);
		new RibbonButton(group1, ImageCache.getImage("olb_picture5.gif"), 
                                 "J2EE", RibbonButton.STYLE_ARROW_DOWN);
		new RibbonButton(group1, ImageCache.getImage("olb_picture6.gif"), 
                                "J2ME", RibbonButton.STYLE_ARROW_DOWN);

		RibbonGroup group2 = new RibbonGroup(tab1, "Miscellaneous", toolTip);
		RibbonButtonGroup buttonGroup = new RibbonButtonGroup(group2);
		new RibbonCheckbox(buttonGroup, "C++", SWT.NONE);
		new RibbonCheckbox(buttonGroup, "PHP", SWT.NONE);
		new RibbonCheckbox(buttonGroup, "PL / SQL", SWT.NONE);
		new RibbonCheckbox(buttonGroup, "Scala", SWT.NONE);

		Menu bigButtonMenu = shell.getBigButtonMenu();
		MenuItem menuItem1 = new MenuItem(bigButtonMenu, SWT.POP_UP);
		menuItem1.setText("Item1");
		MenuItem menuItem2 = new MenuItem(bigButtonMenu, SWT.POP_UP);
		menuItem2.setText("Item2");

		shell.addBigButtonListener(new SelectionListener() {

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
			}

			@Override
			public void widgetSelected(SelectionEvent e) {
				shell.showBigButtonMenu();

			}
		});

		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}
运行上述代码后出来的结果如下:



全文完。


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值