Reputation: 129
I have a JFace dialog which contains SWT Text and a 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.
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
Upvotes: 0
Views: 436
Reputation: 36884
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. It will be enabled once the Text
gaines focus. The Button
will be disabled again after it was pressed.
Upvotes: 1