Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Java GUI 设计
打印话题 寄给朋友 订阅主题 |
作者 | 一个SWT程序,不知道为什么无法实现***能 |
zhjdenis
发贴: 15 积分: 0 |
于 2007-10-28 10:08
建两个列表,完成左右两个列表之间相互插入内容,但是发现界面对了,可是***能无法实现,望高手赐教,谢谢 import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.*;; public class LIST extends Shell { /** * Launch the application * @param args */ public static void main(String args[]) { Display display =new Display(); Shell shell=new Shell(display); //LIST shell = new LIST(display, SWT.SHELL_TRIM); shell.setText("list example"); String[]leftitem= new String[20]; String[]rightitem=new String[0]; for(int i=0;i<20;i++) { leftitem[i]="item"+i; } final List left=new List(shell,SWT.MULTI|SWT.V_SCROLL); left.setItems(leftitem); left.setToolTipText("please select"); left.setBounds(10, 10, 100, 180); final List right=new List(shell,SWT.MULTI|SWT.V_SCROLL); right.setBounds(170, 10, 100, 180); right.setItems(rightitem); right.setToolTipText("selected"); SelectionAdapter listener=new SelectionAdapter(){ public void selection(SelectionEvent e) { Button b=(Button)e.widget; if(b.getText().equals(">")) change(left.getSelection(), left, right); else if(b.getText().equals(">>")) change(left.getItems(), left, right); else if(b.getText().equals("<")) change(right.getSelection(), right, left); else if(b.getText().equals("<<")) change(right.getItems(), right, left); } public void change(String[]select,List from,List to) { for(int i=0;i<select.length;i++) { from.remove(select[i]); to.add(select[i]); } } }; Button b1=new Button(shell,SWT.NONE); b1.setText(">"); b1.setBounds(130, 20, 25, 20); b1.addSelectionListener(listener); Button b2=new Button(shell,SWT.NONE); b2.setText(">>"); b2.setBounds(130, 55, 25, 20); b2.addSelectionListener(listener); Button b3=new Button(shell,SWT.NONE); b3.setText("<"); b3.setBounds(130, 90, 25, 20); b3.addSelectionListener(listener); Button b4=new Button(shell,SWT.NONE); b4.setText("<<"); b4.setBounds(130, 125, 25, 20); b4.addSelectionListener(listener); shell.setSize(350, 250); shell.pack(); shell.open(); //shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } JBuilder使用技巧 |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
5097 | 一个SWT程序,不知道为什么无法实现***能 | zhjdenis | 2458 | 2007-10-28 10:08 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |