我的布局像:
当我第一次按 TAB 按钮时,我想在公司名称 Texfield 上获得焦点,但现在我在添加按钮上获得焦点,我该如何管理它?
我尝试像这样的代码
ChangeFocus(mTextFieldCompanyName, mTextAreaAboutUs);
ChangeFocus(mTextAreaAboutUs, mTextAreaContactUs);
ChangeFocus(mTextAreaContactUs, mButtonVideo);
ChangeFocus(mButtonVideo, mButtonImage);
ChangeFocus(mButtonImage, mButtonSave);
public void ChangeFocus(Control mControlFrom,final Control mControlTo)
{
mControlFrom.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event)
{
if (event.getCode() == KeyCode.TAB)
{
System.out.println("TAB pressed");
mControlTo.requestFocus();
event.consume(); // do nothing
}
}
});
}