gpt4 book ai didi

java - 尝试创建基本的 JFace 应用程序,不确定问题是什么

转载 作者:行者123 更新时间:2023-12-01 14:51:17 27 4
gpt4 key购买 nike

我尝试在 shell 元素下方添加复合元素,但现在按钮小部件未显示。我错过了什么吗?

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class RadioButtonDemo {

/**
* Create radio buttons
*
* @param parent
* Parent widget
* @param labels
* Array of labels for the radio buttons
* @param defaultSelection
* The default button to select
* @return The newly created buttons complete with labels
*/
public final Button[] getRadioButtons(final Composite parent,
final String[] labels, int defaultSelection) {
// some sanity stuff
assert (defaultSelection < labels.length);
assert (!parent.equals(null));

final Button[] buttons = new Button[labels.length];
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new Button(parent, SWT.RADIO);
buttons[i].setText(labels[i]);
buttons[i].setSelection(defaultSelection == i);
}

return buttons;
}

public void showDemo() {
// some setup
final Display display = new Display();

Shell shell = new Shell(display, SWT.DIALOG_TRIM);
// shell.setLayout(new RowLayout());
shell.setSize(new Point(200, 200)); // make it small for the demo
shell.setText("Radio button demo");
shell.setLayout(new FillLayout());

Composite c = new Composite(shell, SWT.NONE);

final String[] labels = new String[] {
"Never delete code coverage launches from history",
"Delete oldest code coverage launches from history" };
final Button[] radioButtons = this.getRadioButtons(c, labels, 0);

shell.pack(); // min-size...
shell.open(); // open shell

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

display.dispose(); // cleanup
}

public static void main(String[] args) {
// new instance
RadioButtonDemo instance = new RadioButtonDemo();
instance.showDemo();

}
}

最佳答案

您需要设置layoutc 上,例如

Composite c = new Composite(shell, SWT.NONE);
c.setLayout(new FillLayout());

关于java - 尝试创建基本的 JFace 应用程序,不确定问题是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14815194/

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