我的布局如:
当我第一次按下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
}
}
});
}
答案 0 :(得分:6)
尝试将mTextFieldCompanyName包装在Platform.runLater()
Platform.runLater(new Runnable() {
@Override
public void run() {
mTextFieldCompanyName.requestFocus();
}
});
希望有所帮助:)