SWT中的可重复组合 [英] Focusable composite in SWT

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

问题描述

我们有一个自定义控件,它本质上是一个带有标签和按钮的组合。目前当用户按Tab时,焦点就转到按钮上了。



如何使复合材料接收焦点,按钮被排除在焦点之外?例如。用户应该能够选择所有的自定义控件,而不是停止按钮。



更新:我们的控件树如下所示: p>


  • 主窗格

    • CustomPanel1

      • 标签

      • 按钮


    • CustomPanel2

      • 标签

      • 按钮


    • CustomPanel3

      • 标签

      • 按钮





    • 所有CustomPanel都是同一个Composite子类。我们需要的是让标签在这些面板之间循环,而不是看到按钮(这些是唯一可重点组件)

      解决方案

      p>您可以使用 Composite 的标签顺序.doc.isv / reference / api / org / eclipse / swt / widgets / Composite.html#setTabList%28org.eclipse.swt.widgets.Control%5b%5d%29rel =nofollow> Composite#setTabList(Control [])



      这是一个小例子,它将在按钮 s 一个忽略 / code> s 两个

        public static void main(String [] args){
      显示display = new Display();
      Shell shell = new Shell(display);
      shell.setLayout(new GridLayout(1,false));

      复合内容= new Composite(shell,SWT.NONE);
      content.setLayout(new GridLayout(2,true));
      content.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));

      final Button one = new Button(content,SWT.PUSH);
      one.setText(One);

      final Button two = new Button(content,SWT.PUSH);
      two.setText(Two);

      final Button 3 = new Button(content,SWT.PUSH);
      three.setText(Three);

      final Button four = new Button(content,SWT.PUSH);
      four.setText(Four);

      Control [] controls = new Control [] {one,three};

      content.setTabList(controls);

      shell.pack();
      shell.open();
      while(!shell.isDisposed()){
      if(!display.readAndDispatch()){
      display.sleep();
      }
      }
      display.dispose();
      }

      编辑:上面的代码可以轻松转换以满足您的要求。我不能自己测试,因为复合不能专注,但你应该得到这样的想法:



      mainPane.setTabList(new Control [] {customPanel1,customPanel2,customPanel3});

        

      customPanel1.setTabList(new Control [] {});
      customPanel2.setTabList(new Control [] {});
      customPanel3.setTabList(new Control [] {});


      We have a custom control that is essentially a composite with label and a button. Currently when the user presses "Tab" the focus comes to the button.

      How can I make the composite to receive focus and the button to be excluded from the focus? E.g. the user should be able to tab through all custom controls and not stop at buttons.

      Updated: Our controls tree looks like this:

      • Main pane
        • CustomPanel1
          • Label
          • Button
        • CustomPanel2
          • Label
          • Button
        • CustomPanel3
          • Label
          • Button

      All CustomPanel's are of the same Composite subclass. What we need is for the tab to cycle between those panels and do not "see" buttons (those are the only focusable components)

      解决方案

      You can define the tab order of a Composite by using Composite#setTabList(Control[]).

      Here is a small example that will tab between the Buttons one and three ignoring the Buttons two and four:

      public static void main(String[] args) {
          Display display = new Display();
          Shell shell = new Shell(display);
          shell.setLayout(new GridLayout(1, false));
      
          Composite content = new Composite(shell, SWT.NONE);
          content.setLayout(new GridLayout(2, true));
          content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
      
          final Button one = new Button(content, SWT.PUSH);
          one.setText("One");
      
          final Button two = new Button(content, SWT.PUSH);
          two.setText("Two");
      
          final Button three = new Button(content, SWT.PUSH);
          three.setText("Three");
      
          final Button four = new Button(content, SWT.PUSH);
          four.setText("Four");
      
          Control[] controls = new Control[] {one, three};
      
          content.setTabList(controls);
      
          shell.pack();
          shell.open();
          while (!shell.isDisposed()) {
              if (!display.readAndDispatch()) {
                  display.sleep();
              }
          }
          display.dispose();
      }
      

      EDIT: The code above can easily be converted to fit your requirements. I can't test it myself, because Composites aren't focus-able, but you should get the idea:

      mainPane.setTabList(new Control[] {customPanel1, customPanel2, customPanel3 });
      
      customPanel1.setTabList(new Control[] {});
      customPanel2.setTabList(new Control[] {});
      customPanel3.setTabList(new Control[] {});
      

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

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