如何通过拖动角来调整复合材料的大小 [英] How do I make it possible to resize a composite by dragging the corner

查看:50
本文介绍了如何通过拖动角来调整复合材料的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SWT,我希望能够通过拖动它的角来调整复合材料的大小,就像调整外壳的大小一样.我敢肯定有人已经实施了一个很好的解决方案.谢谢.

I am working with SWT and I would like to be able to resize a composite by dragging the corner of it, the same way that you can resize a shell. I'm sure someone out there has implemented a good solution. Thanks.

推荐答案

我认为您正在寻找的内容可以通过 org.eclipse.swt.widgets.Tracker

I think what you are looking for can be implemented with org.eclipse.swt.widgets.Tracker

这是示例工作代码:

public static void main(String[] args) {

    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.open();

    final Composite b = new Composite(shell, SWT.NONE);
    b.setBounds(20, 20, 80, 80);
    b.setBackground(display.getSystemColor(SWT.COLOR_BLUE));

    b.addListener(SWT.MouseDown, new Listener() {

      public void handleEvent(Event e) {

        Tracker tracker = new Tracker(b.getParent(), SWT.RESIZE);
        tracker.setStippled(true);
        Rectangle rect = b.getBounds();
        tracker.setRectangles(new Rectangle[] { rect });
        if (tracker.open()) {
          Rectangle after = tracker.getRectangles()[0];
          b.setBounds(after);
        }
        tracker.dispose();
      }
    });
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }  

这篇关于如何通过拖动角来调整复合材料的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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