이것은 당신이 원하는 일을해야합니다
private static String textContent = "";
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout(SWT.VERTICAL));
Text text = new Text(shell, SWT.BORDER);
text.addListener(SWT.FocusOut, new Listener()
{
@Override
public void handleEvent(Event e)
{
Text text = (Text) e.widget;
textContent = text.getText();
text.setText(textContent.substring(0, Math.min(10, textContent.length())) + "...");
}
});
text.addListener(SWT.FocusIn, new Listener()
{
@Override
public void handleEvent(Event e)
{
Text text = (Text) e.widget;
text.setText(textContent);
}
});
Button button = new Button(shell, SWT.PUSH);
button.setText("Lose focus");
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
그것은 이벤트를 초점을 듣고 너무 긴 경우 가시 String
을 자릅니다.
이는 모습입니다 :
이유 왜 코드가 작동하지 않습니다 :
초점없이 : 초점
다음과 같습니다 : 당신이 c 모두 wakeupPatternText.setText(wakeup);
VerifyListener
에서 수신자 자체가 재귀 적으로 다시 호출됩니다.
출처
2013-04-22 09:03:50
Baz
뭔가를 시도한 경우 항상 시도한 것을 설명하십시오. – Baz
로그를 출력하여 디버깅 할 수 있습니까? 도움이 필요하면 작성한 코드 스 니펫을 표시하십시오. 가져 오기 부분은 청취자 여야하며, 그 안에있는 텍스트의 부분 문자열이어야합니다. –
@Baz 수정 리스너를 추가하려고했지만 주 문제점은 30 자의 텍스트가 있고 내 텍스트 상자가 15 자만 지원한다는 것입니다.하지만 내 버튼이 텍스트 상자로 바인드됨에 따라 (...) 유효하지 않은 값으로 처리됩니다. – Rajesh