gpt4 book ai didi

java - 寻找带有抓手的可调整大小的 SWT (JFace) 文本区域组件

转载 作者:行者123 更新时间:2023-11-30 07:02:41 25 4
gpt4 key购买 nike

我希望在我的 Eclipse 插件之一中有一个可调整大小的文本区域。它的右下角应该有一个抓手,可以拖动它来更改文本区域的大小,类似于以下 html 示例:

<!DOCTYPE html>
<html>
<body>

<textarea rows="4" cols="50">
This is a resizable html text area with a gripper at the lower right corner. How to create something similar with SWT JFace?</textarea>

</body>
</html>

结果为静态图像: Result as Image

我已经能够创建 SWT 多行文本:

Text  textArea = toolkit.createText(parentContainer, "Default text", SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
textArea.setEnabled(isEnabled());
textArea.setToolTipText("tooltip");

GridData areaData = new GridData();
areaData.grabExcessHorizontalSpace = true;
areaData.horizontalAlignment = GridData.FILL;
areaData.verticalAlignment = GridData.FILL;
areaData.grabExcessVerticalSpace = true;
areaData.heightHint = 80;
areaData.widthHint = 200;
textArea.setLayoutData(areaData);

enter image description here

我想要一个能够垂直和水平调整文本字段大小的夹具,而不是滚动条。

文本元素的文档在这里,我找不到抓手选项: http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fwidgets%2FText.html

如何向文本添加抓手?

是否有一个带有夹具的可调整大小的面板,可以用来包裹文本?“Sash”似乎只能在一个方向上调整大小: Can you create a resizable control in SWT?

是否有一个成品控件可以提供我正在寻找的功能? (我查看了星云小部件,但似乎没有带有抓手的文本区域组件。)

最佳答案

在 Baz 的帮助下,我找到了以下解决方案。它并不完美,但可以工作,并且可以作为其他人的起点。请注意,父布局尚未适应新尺寸。下面的示例尚未设置矩形大小的最小值。

    //toolkit
FormToolkit toolkit = new FormToolkit(Display.getCurrent());

//create content composite for label, text area and gripper
contentContainer = toolkit.createComposite(parent);

GridData fillHorizontal = new GridData();
fillHorizontal.grabExcessHorizontalSpace = true;
fillHorizontal.horizontalAlignment = GridData.FILL;
contentContainer.setLayoutData(fillHorizontal);

GridLayout gridLayout = new GridLayout(1, true);
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 2;
gridLayout.marginHeight = 2;
gridLayout.marginWidth = 0;
contentContainer.setLayout(gridLayout);

//label
String currentLabel = getLabel();
toolkit.createLabel(contentContainer, currentLabel);

//text area
textArea = toolkit.createText(contentContainer, get(), SWT.MULTI | SWT.BORDER | SWT.WRAP);
textArea.setEnabled(isEnabled());
textArea.setToolTipText(tooltip);

GridData areaData = new GridData();
areaData.grabExcessHorizontalSpace = true;
areaData.grabExcessVerticalSpace = true;
areaData.horizontalAlignment = GridData.FILL;
areaData.verticalAlignment = GridData.FILL;
areaData.widthHint = 200;
areaData.heightHint = 80;
textArea.setLayoutData(areaData);

//gripper
org.eclipse.swt.widgets.Label gripper = toolkit.createLabel(contentContainer, "");
gripper.setImage(Activator.getImage("tracker.png"));

GridData tragData = new GridData();
tragData.horizontalAlignment = GridData.END;
gripper.setLayoutData(tragData);

Listener trackerListener = new Listener() {

@Override
public void handleEvent(Event e) {

Tracker tracker = new Tracker(contentContainer.getParent(), SWT.RESIZE | SWT.DOWN | SWT.RIGHT);
Rectangle maxRect = contentContainer.getParent().getBounds();
Rectangle rect = contentContainer.getBounds();
tracker.setRectangles(new Rectangle[] { rect });
if (tracker.open()) {
Rectangle after = tracker.getRectangles()[0];
Rectangle newRect = new Rectangle(
after.x,
after.y,
Math.min(after.width, maxRect.width - 10),
Math.min(after.height, maxRect.height - 10));
contentContainer.setBounds(newRect);
}
tracker.dispose();
}
};

gripper.addListener(SWT.MouseDown, trackerListener);

enter image description here

关于java - 寻找带有抓手的可调整大小的 SWT (JFace) 文本区域组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40627104/

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