SWT进阶版-切换按钮 箭头按钮

package demotest;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

/**
 * 
 * @author mositure
 * 切换按钮  箭头按钮
 */
public class Test_three {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//定义Display
		Display display = new Display();
		//创建窗口
		Shell shell = new Shell(display,SWT.SHELL_TRIM);
		shell.setSize(500, 750);
		shell.setText("分组实列");
		//设置窗口布局
		shell.setLayout(new FillLayout(SWT.VERTICAL));
		
		//在当前窗口创建分组
		Group group = new Group(shell, SWT.SHADOW_ETCHED_OUT);
		group.setText("设置组名");
		group.setLayout(new FillLayout(SWT.VERTICAL));
		//切换按钮
		Button button = new Button(group,SWT.TOGGLE|SWT.LEFT);
		button.setText("SWT.LEFT");
		button.setToolTipText("SWT.LEFT");
		
		Button button1 = new Button(shell,SWT.TOGGLE|SWT.FLAT);
		button1.setText("SWT.FLAT");
		button1.setToolTipText("SWT.FLAT");
		
		Button button2 = new Button(shell,SWT.TOGGLE|SWT.BORDER);
		button2.setText("SWT.BORDER");
		button2.setToolTipText("SWT.BORDER");
		
		//箭头按钮 SWT.UP 上| SWT.DOWN 下| SWT.LEFT 左|SWT.RIGHT 右|SWT.FLAT 中|SWT.BORDER|
		Button button3 = new Button(shell,SWT.ARROW|SWT.UP);   
		button3.setText("SWT.LEFT");
		button3.setToolTipText("SWT.LEFT");
		
		//单选按钮
		Button button4 = new Button(shell,SWT.RADIO|SWT.UP);   
		button4.setText("SWT.LEFT");
		button4.setToolTipText("SWT.LEFT");
		
		//多选按钮
		Button button5 = new Button(shell,SWT.CHECK|SWT.UP);   
		button5.setText("SWT.LEFT");
		button5.setToolTipText("SWT.LEFT");
		//多选实列
		final Button[] buttons = new Button[4];
		String[] str = {"多选1","多选2","多选3","多选4"};
		for(int i=0;i<buttons.length;i++){
			buttons[i] = new Button(shell,SWT.CHECK);  
			buttons[i].setText(str[i]);
		}
		
		Button bt = new Button(shell, SWT.NONE);
		bt.setText("OK");

		bt.addSelectionListener(new SelectionListener() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				//循环所有按钮
				for(int j=0;j<buttons.length;j++){
					//如果选中则输出选中的值
					if(buttons[j].getSelection()){
						System.out.println("您选择了:"+buttons[j].getText());
					}
				}
			}
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
			}
		});
		
		group.getLayout();
		shell.getLayout();
		//打开主窗体
		shell.open();
//		shellDig.open();
		//如果主窗体没有关闭
		while(!shell.isDisposed()){ 
			//如果display不忙
			if(!display.readAndDispatch()){  
				  //休眠
				display.sleep();  
			}
		}
		//销毁display
		display.dispose();    
	}

}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骑猪撞树-小码农

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值