SWT/Jface学习笔记4(popuplist)

时间:2022-07-25 22:22:47

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

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

开发环境 elipse+swtdesigner

代码:

SWT/Jface学习笔记4(popuplist)import  org.eclipse.swt.SWT;
SWT/Jface学习笔记4(popuplist)
import  org.eclipse.swt.custom.PopupList;
SWT/Jface学习笔记4(popuplist)
import  org.eclipse.swt.events.SelectionAdapter;
SWT/Jface学习笔记4(popuplist)
import  org.eclipse.swt.events.SelectionEvent;
SWT/Jface学习笔记4(popuplist)
import  org.eclipse.swt.widgets.Button;
SWT/Jface学习笔记4(popuplist)
import  org.eclipse.swt.widgets.Display;
SWT/Jface学习笔记4(popuplist)
import  org.eclipse.swt.widgets.Shell;
SWT/Jface学习笔记4(popuplist)
SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)
public   class  PopuplistTT  ... {
SWT/Jface学习笔记4(popuplist)
SWT/Jface学习笔记4(popuplist)    
protected Shell shell;
SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)    
private static final String [] PUSH = ...{"0","1","2","3","4","5"};
SWT/Jface学习笔记4(popuplist)
SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)    
/** *//**
SWT/Jface学习笔记4(popuplist)     * Launch the application
SWT/Jface学习笔记4(popuplist)     * 
@param args
SWT/Jface学习笔记4(popuplist)     
*/

SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)    
public static void main(String[] args) ...{
SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)        
try ...{
SWT/Jface学习笔记4(popuplist)            PopuplistTT window 
= new PopuplistTT();
SWT/Jface学习笔记4(popuplist)            window.open();
SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)        }
 catch (Exception e) ...{
SWT/Jface学习笔记4(popuplist)            e.printStackTrace();
SWT/Jface学习笔记4(popuplist)        }

SWT/Jface学习笔记4(popuplist)    }

SWT/Jface学习笔记4(popuplist)
SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)    
/** *//**
SWT/Jface学习笔记4(popuplist)     * Open the window
SWT/Jface学习笔记4(popuplist)     
*/

SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)    
public void open() ...{
SWT/Jface学习笔记4(popuplist)        
final Display display = Display.getDefault();
SWT/Jface学习笔记4(popuplist)        createContents();
SWT/Jface学习笔记4(popuplist)        shell.open();
SWT/Jface学习笔记4(popuplist)        shell.layout();
SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)        
while (!shell.isDisposed()) ...{
SWT/Jface学习笔记4(popuplist)            
if (!display.readAndDispatch())
SWT/Jface学习笔记4(popuplist)                display.sleep();
SWT/Jface学习笔记4(popuplist)        }

SWT/Jface学习笔记4(popuplist)    }

SWT/Jface学习笔记4(popuplist)
SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)    
/** *//**
SWT/Jface学习笔记4(popuplist)     * Create contents of the window
SWT/Jface学习笔记4(popuplist)     
*/

SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)    
protected void createContents() ...{
SWT/Jface学习笔记4(popuplist)        shell 
= new Shell();
SWT/Jface学习笔记4(popuplist)        shell.setSize(
500375);
SWT/Jface学习笔记4(popuplist)        shell.setText(
"SWT Application");
SWT/Jface学习笔记4(popuplist)
SWT/Jface学习笔记4(popuplist)        
final Button button = new Button(shell, SWT.NONE);
SWT/Jface学习笔记4(popuplist)        button.setText(
"点击我");
SWT/Jface学习笔记4(popuplist)        button.setBounds(
0010023);
SWT/Jface学习笔记4(popuplist)        
SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)        button.addSelectionListener(
new SelectionAdapter()...{
SWT/Jface学习笔记4(popuplist)SWT/Jface学习笔记4(popuplist)            
public void widgetSelected(SelectionEvent event)...{
SWT/Jface学习笔记4(popuplist)                PopupList list 
= new PopupList(shell);
SWT/Jface学习笔记4(popuplist)                list.setItems(PUSH);
SWT/Jface学习笔记4(popuplist)                String selected 
= list.open(shell.getBounds());
SWT/Jface学习笔记4(popuplist)                System.out.println(selected);
SWT/Jface学习笔记4(popuplist)            }

SWT/Jface学习笔记4(popuplist)        }
);        
SWT/Jface学习笔记4(popuplist)    }

SWT/Jface学习笔记4(popuplist)
SWT/Jface学习笔记4(popuplist)}

SWT/Jface学习笔记4(popuplist)