Topic: 一个SWT程序,不知道为什么无法实现***能

  Print this page

1.一个SWT程序,不知道为什么无法实现***能 Copy to clipboard
Posted by: zhjdenis
Posted on: 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();
  }


   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