【发布时间】:2019-11-05 10:00:12
【问题描述】:
我正在尝试使用 GTK 的 java-gnome 绑定来显示一个简单的对话框,其中包含两个按钮和一个用于用户输入的文本字段。这就是我所拥有的:
import org.gnome.gtk.*;
import org.gnome.pango.FontDescription;
public class GrepDialog extends Dialog {
private Entry entry;
public GrepDialog(Window parent) {
super("Grep", parent, false);
this.setDefaultSize(320, 100);
this.setResizable(false);
this.entry = new Entry("regex is going to be here");
this.entry.overrideFont(new FontDescription("Monospace, 14"));
this.add(entry);
this.addButton(Stock.FIND, ResponseType.OK);
this.addButton(Stock.CANCEL, ResponseType.CANCEL);
}
public String getRegex() {
return entry.getText();
}
}
我创建了一个新的 GrepDialog,调用 .run(),我只能看到两个按钮,没有文本条目。
【问题讨论】:
-
我暂时修复了这个在构造函数末尾添加
this.getChild().showAll();,但我不认为这是一个有效的解决方案 -
你必须把 this.add(entry) 改成 this.getContentArea().add(entry)