开发者

Disable copy paste in SWT Text Component

开发者 https://www.devze.com 2022-12-24 17:37 出处:网络
I\'m using SWT Text component. Do someone know how can I prevent copy/p开发者_如何学编程aste operation for the Text component.

I'm using SWT Text component. Do someone know how can I prevent copy/p开发者_如何学编程aste operation for the Text component.

Thanks Subha


A crude way of doing this would be to disable the control-key modifier on the Text box.

    text.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent event) {

        }

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.stateMask == 262144) {
                event.doit = false;
            }

        }
    });

Plus you may also want to disable the right click on the text box (use a MouseListener with the same trick).


I done this by simply setting my own menu with no menu items at all.

      ((Text) textFirstNameEntry).setMenu(new Menu(shell, 0));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号