[英]Appropriate Listener for SWT Text
I have a JFace dialog which contains SWT Text and a button . 我有一个JFace对话框,其中包含SWT Text和一个button。 Initially when the dialog is opened the button should be disabled, and when I click on the
Text
and as long as the caret position of the Text
is visible button should be enabled. 最初,当打开对话框时,应该禁用该按钮,而当我单击“
Text
,只要启用“ Text
的插入符号位置,就应该启用该按钮。
These are the listeners i am using : 这些是我正在使用的听众:
text.addMouseListener(new MouseListener()
{
@Override
public void mouseDoubleClick(MouseEvent arg0)
{
}
@Override
public void mouseDown(MouseEvent arg0)
{
}
@Override
public void mouseUp(MouseEvent arg0)
{
testButton.setEnabled(true);
}
});
text.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent arg0)
{
testButton.setEnabled(false);
}
@Override
public void focusGained(FocusEvent arg0)
{
}
});
Am I using the appropriate listeners? 我在使用适当的听众吗? Please suggest
请建议
If I understood you correctly, this should be what you want: 如果我对您的理解正确,那么应该是您想要的:
button.setEnabled(false);
button.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event arg0)
{
button.setEnabled(false);
}
});
text.addListener(SWT.FocusIn, new Listener()
{
@Override
public void handleEvent(Event e)
{
button.setEnabled(true);
}
});
Initially, the Button
is disabled. 最初,
Button
被禁用。 It will be enabled once the Text
gaines focus. 一旦
Text
焦点,它将被启用。 The Button
will be disabled again after it was pressed. Button
后将再次被禁用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.