gpt4 book ai didi

java - SWT 拖放自定义控件显示在光标旁边

转载 作者:行者123 更新时间:2023-11-30 04:53:46 25 4
gpt4 key购买 nike

在 SWT 中拖动时,如何在光标旁边显示一些自定义控件或小部件?

喜欢按钮、树或表格,而不是图像。

如果不可能 - 我如何将这样的按钮渲染到图像中?

最佳答案

我找到了使用 GC( Canvas )类将任意控件(小部件)渲染为图像的方法。方法如下:

dragSource.addDragListener(new DragSourceListener() {
@Override
public void dragStart(DragSourceEvent dragSourceEvent) {
// getting control widget - Composite in this case
Composite composite = (Composite) ((DragSource) dragSourceEvent.getSource()).getControl();
// Getting dimensions of this widget
Point compositeSize = composite.getSize();
// creating new GC
GC gc = new GC(composite);
// Creating new Image
Image image = new Image(Display.getCurrent(),compositeSize.x,compositeSize.y);
// Rendering widget to image
gc.copyArea(image,0,0);
// Setting widget to DnD image
dragSourceEvent.image = image;
}
... other overriden methods ...
}

关于java - SWT 拖放自定义控件显示在光标旁边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9227206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com