0

这是我的完整编码。我有两个类第一个 MyDateTime,第二个是员工。我已经包含了我当前工作的编码。对于 EmployeePart 类,AbstractEditorPart 是我们自己的父类,它是扩展的

public class MyDateTime extends DateTime{

    public DateTime(Composite parent, int style) 
    { 
        super(parent, style); 
    }

    public Date getValue() 
    { 
        Date date = new Date(getYear(), getMonth(), getDay()); 
        return date; 
    }
}




public Class EmployeePart extends AbstractEditorPart(
private MyDateTime currentDate;

public void createBody(Composite parent){
currentDate=Util.createDateChooserCombo(parent, toolkit, "Date:", 2);

}

public void save(Employee input){
return null;
}
}

}
4

1 回答 1

0

结果比我最初想象的要复杂一些。

一种解决方案是为TabList包含CompositeWidget的 s 的 定义一个。这样,您可以首先定义您希望它们被遍历的顺序。

然后将 a 添加到您要遍历的Listener每个s 中。WidgetListener将确定 中的下一个项目,并在按下或TabList时强制将焦点放在该项目上。TabEnter

这是一些示例代码:

public static void main(String[] args)
{
    Display display = Display.getDefault();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    final Composite content = new Composite(shell, SWT.NONE);
    content.setLayout(new FillLayout());

    Text first = new Text(content, SWT.BORDER);
    Text second = new Text(content, SWT.BORDER);

    content.setTabList(new Control[] {first, second});

    Listener enterListener = new Listener()
    {
        @Override
        public void handleEvent(Event event)
        {
            /* Is it a traverse via Tab or Enter? */
            if(event.keyCode == SWT.CR || event.keyCode == SWT.TRAVERSE_RETURN || event.keyCode == SWT.TRAVERSE_TAB_NEXT)
            {
                /* Get source of event */
                Widget source = event.widget;

                /* Get traverse order of content composite */
                Control[] tabList = content.getTabList();

                /* Try to find current position in the tab list */
                for(int i = 0; i < tabList.length; i++)
                {
                    if(source.equals(tabList[i]))
                    {
                        /* Get the next item in the tab list */
                        Control nextControl = tabList[(i + 1) % tabList.length];

                        /* And force the focus on this item */
                        nextControl.setFocus();
                        nextControl.forceFocus();

                        return;
                    }
                }
            }
        }
    };

    first.addListener(SWT.KeyUp, enterListener);
    second.addListener(SWT.KeyUp, enterListener);

    shell.pack();
    shell.open();

    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
于 2013-04-12T09:28:25.287 回答