GTK 中的自定义对话框不显示任何内容
Custom Dialog in GTK doesn;t show anything
我正在尝试使用 java-GTK 的 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,调用 .运行(),我只能看到两个按钮,没有文本条目。
在 GTK2 和 GTK3 中,小部件默认情况下是隐藏的。所以你必须用 gtk_widget_show()
明确地让它可见。在这里,您可以执行 this.entry.show()
(和类似的,对于创建的每个小部件)。
或者,您可以在添加所有小部件后对父容器执行 gtk_widget_show_all()
(例如,this.showAll()
),这将使每个子项都可见。
在 GTK4 中,小部件默认可见。所以这在 GTK4 中不需要(当你有 java-gnome 支持 GTK4 时)。
我正在尝试使用 java-GTK 的 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,调用 .运行(),我只能看到两个按钮,没有文本条目。
在 GTK2 和 GTK3 中,小部件默认情况下是隐藏的。所以你必须用 gtk_widget_show()
明确地让它可见。在这里,您可以执行 this.entry.show()
(和类似的,对于创建的每个小部件)。
或者,您可以在添加所有小部件后对父容器执行 gtk_widget_show_all()
(例如,this.showAll()
),这将使每个子项都可见。
在 GTK4 中,小部件默认可见。所以这在 GTK4 中不需要(当你有 java-gnome 支持 GTK4 时)。