Appropriate Listener for SWT Text

会有一股神秘感。 提交于 2019-12-11 19:44:24

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/19348411/appropriate-listener-for-swt-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!