SWT/Jface学习笔记4(popuplist)

这段程序是 创建一个名为“点击我”的button,当你按下这个button时回出现一个list列表,点击list里面的内容,会在eclipse控制台输出相应的内容。 

这个程序有个小问题,就是点击button后在界面的下方出现一个list,而不是在button下面出现一个list,我想要在button下面显示一个list,但是不知道怎么做,还请高手指点一下 谢谢啦^_^。

开发环境 elipse+swtdesigner

代码:

import  org.eclipse.swt.SWT;
import  org.eclipse.swt.custom.PopupList;
import  org.eclipse.swt.events.SelectionAdapter;
import  org.eclipse.swt.events.SelectionEvent;
import  org.eclipse.swt.widgets.Button;
import  org.eclipse.swt.widgets.Display;
import  org.eclipse.swt.widgets.Shell;

public   class  PopuplistTT  {

    
protected Shell shell;
    
private static final String [] PUSH = {"0","1","2","3","4","5"};

    
/**
     * Launch the application
     * 
@param args
     
*/

    
public static void main(String[] args) {
        
try {
            PopuplistTT window 
= new PopuplistTT();
            window.open();
        }
 catch (Exception e) {
            e.printStackTrace();
        }

    }


    
/**
     * Open the window
     
*/

    
public void open() {
        
final Display display = Display.getDefault();
        createContents();
        shell.open();
        shell.layout();
        
while (!shell.isDisposed()) {
            
if (!display.readAndDispatch())
                display.sleep();
        }

    }


    
/**
     * Create contents of the window
     
*/

    
protected void createContents() {
        shell 
= new Shell();
        shell.setSize(
500375);
        shell.setText(
"SWT Application");

        
final Button button = new Button(shell, SWT.NONE);
        button.setText(
"点击我");
        button.setBounds(
0010023);
        
        button.addSelectionListener(
new SelectionAdapter(){
            
public void widgetSelected(SelectionEvent event){
                PopupList list 
= new PopupList(shell);
                list.setItems(PUSH);
                String selected 
= list.open(shell.getBounds());
                System.out.println(selected);
            }

        }
);        
    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值