gpt4 book ai didi

java - 用于选择字符串组(标签)的简单控件/组件

转载 作者:行者123 更新时间:2023-12-01 22:42:11 25 4
gpt4 key购买 nike

我需要一些 swt 组件,我可以用它来选择/取消选择一组字符串。我需要一个类似于这个的结构, https://code.google.com/a/eclipselabs.org/p/opal/wiki/Checkboxgroup

然而,上述解决方案对于我的要求来说有点过分了。我想知道是否可以使用任何其他 swt 组件来实现相同的功能。(例如,如果一棵树只允许根级选择而不是子级选择,那么这对我来说是最好的)

最佳答案

好的,这是一个没有的示例。它使用 Composite 来保存 Button 和另一个 Composite 来保存 Label:

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

MyGroup first = new MyGroup(shell, SWT.BORDER);
first.setHeader("A");
first.addStrings("A1 A1 A1 A1 A1 A1 A1 A1", "A2 A2 A2 A2 A2 A2", "A3 A3 A3 A3");

MyGroup second = new MyGroup(shell, SWT.BORDER);
second.setHeader("B");
second.addStrings("B1", "B2");

shell.pack();
shell.open();

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

private static class MyGroup extends Composite
{
private Button button;
private Composite content;

public MyGroup(Composite parent, int style)
{
super(parent, style);

setLayout(new GridLayout(1, false));
setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

button = new Button(this, SWT.CHECK);
content = new Composite(this, SWT.NONE);

GridLayout layout = new GridLayout(1, false);
layout.marginLeft = 20;

content.setLayout(layout);
content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
}

public void setHeader(String header)
{
button.setText(header);
}

public void addStrings(String... strings)
{
for (String string : strings)
new Label(content, SWT.NONE).setText(string);
}
}

看起来像这样:

enter image description here

关于java - 用于选择字符串组(标签)的简单控件/组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25976932/

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