在SWT中制作复合材料 [英] Making composite focusable in SWT

查看:196
本文介绍了在SWT中制作复合材料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能在SWT中创建一个可调焦的组合?我通过显示过滤器捕获所有键盘事件,但是当焦点位于树或列表上时会出现一些问题 - GTK +的默认操作是在控件的内容中搜索。



我想要做的是将SWT和AWT与可聚焦的AWT组件混合。我设法使AWT小部件不可聚焦,我添加了显示过滤器,使AWT组件接收键盘事件(但不是直接),即使它没有被聚焦。但是,当一些SWT控件集中时,有几个问题 - 这就是为什么我想要复合可聚焦。所以我的最后一个问题是:是否有可能使SWT组合可聚焦如果 Composite 包含子窗口小部件,则默认操作是选择时放弃焦点。为了避免这种情况,首先扩展 Composite 类,如下所示:

 类FocusableComposite扩展复合
{
public FocusableComposite(Composite parent,int style)
{
super(parent,style);


public boolean setFocus()
{
return super.forceFocus();然后使用 MouseListener
$ b

/ code>在FocusableComposite的一个新实例上直接点击 Composite 时直接调用setFocus():

  Composite composite = new FocusableComposite(shell,SWT.NONE); 

composite.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent event)
{
((Composite)event.widget)。 setFocus();
}
});


Is it possible to create a focusable composite in SWT? I'm catching all keyboard events via Display filter, but there are some problems when the focus is on the tree or list - GTK+'s default action is to search in the contents of the control.

What I want to do is to mix SWT and AWT with focusable AWT component. I managed to make the AWT widget unfocusable and I added Display filter to make the AWT component receiving keyboard events (but not directly), even when it's not focused. But there are several problems when some SWT controls are focused - that's why I want to make composite focusable.

So my final question is: is it possible to make SWT composite focusable?

解决方案

If a Composite contains child widgets, the default action is to give up focus when it is selected. To circumvent this, start by extending the Composite class as such:

class FocusableComposite extends Composite
{
    public FocusableComposite(Composite parent, int style)
    {
        super(parent, style);
    }

    public boolean setFocus()
    {
        return super.forceFocus();
    }
}

Then use a MouseListener on a new instantiation of FocusableComposite to call setFocus() directly whenever the Composite is clicked:

Composite composite = new FocusableComposite(shell, SWT.NONE);

composite.addMouseListener(new MouseAdapter()
{
    public void mouseDown(MouseEvent event)
    {
        ((Composite)event.widget).setFocus();
    }
});

这篇关于在SWT中制作复合材料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆