4
JavaFX 2에서 startEdit() 메서드를 재정 의하여 포커스를 요청하는 사용자 정의 TableCell을 만들었습니다. 따라서 셀에서 edit 명령을 호출하자마자 나타나는 편집 텍스트 필드에 초점이 맞춰집니다.JavaFX 2 테이블 뷰에서 캐럿 위치 설정 포커스를 요청한 후 TextField 편집
다음 단계는 텍스트 필드의 끝에 캐럿 위치를 설정하는 것입니다. 그러나 알 수없는 이유로 그것은 효과가없는 것 같습니다. 항상 첫 번째 문자 앞에 놓입니다.
public void startEdit() {
if (!isEmpty()) {
super.startEdit();
createTextField();
setText(null);
textField.end();
setGraphic(textField);
((TextField)getGraphic()).end();
textField.end();
Platform.runLater(
new Runnable() {
@Override
public void run() {
getGraphic().requestFocus();
}
});
}
}
public void startEdit() {
if (!isEmpty()) {
super.startEdit();
createTextField();
setText(null);
setGraphic(textField);
textField.end();
Platform.runLater(
new Runnable() {
@Override
public void run() {
getGraphic().requestFocus();
textField.end();
((TextField)getGraphic()).end();
}
});
}
}
public void startEdit() {
if (!isEmpty()) {
super.startEdit();
createTextField();
setText(null);
textField.end();
setGraphic(textField);
((TextField)getGraphic()).end();
getGraphic().requestFocus();
((TextField)getGraphic()).end();
textField.end();
}
}
논리적 접근 방식은 텍스트 필드에 초점을 요청하고 캐럿을 이동하는 것입니다,하지만 어느 이유로 작동하지 않는 것 : 여기
는 지금까지 시도 것입니다.
어쩌면 누군가가 나를 계몽 수 있습니까?
당신은 좀 더 노출 – thecoshman
을 얻을 수있는 몇 가지 더 관련 태그를 추가하려고합니다 텍스트가 texfield 내부 있습니까 편집 모드로 변경하는 경우? Platform.runlater에서 try textfield.setText ("some text"); 캐럿이있는 곳을 확인하십시오. –
@ uluk-biy 예, 편집 모드로 변경할 때 필드 안에 텍스트가 있습니다. 이후에 requestFocus() 및 setText()를 호출하면 캐럿은 여전히 첫 번째 문자 앞에옵니다. – crisi