简体   繁体   English

GTK 中的自定义对话框不显示任何内容

[英]Custom Dialog in GTK doesn;t show anything

I'm trying to display a simple dialog with two buttons and a text field for user input using java-gnome bindings for GTK.我正在尝试使用 GTK 的 java-gnome 绑定显示一个带有两个按钮和一个用于用户输入的文本字段的简单对话框。 This is what I have:这就是我所拥有的:

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();
    }
}

I create a new GrepDialog, call.run() and I can see only two buttons and no text entries.我创建了一个新的 GrepDialog,call.run(),我只能看到两个按钮,没有文本条目。

In GTK2 and GTK3, widgets are hidden by default.在 GTK2 和 GTK3 中,小部件默认是隐藏的。 So you have to explicitly make it visible with gtk_widget_show() .因此,您必须使用gtk_widget_show()显式使其可见。 Here, you can do this.entry.show() (and similar, for every widget created).在这里,您可以执行this.entry.show() (和类似的,对于创建的每个小部件)。

Alternately, you can do gtk_widget_show_all() (Eg., this.showAll() ) on the parent container after all widgets are added which will make every children visible.或者,您可以在添加所有小部件后在父容器上执行gtk_widget_show_all() (例如this.showAll() ),这将使每个孩子都可见。

In GTK4, widgets are visible by default.在 GTK4 中,小部件默认是可见的。 So this won't be required in GTK4 (when you have java-gnome supporting GTK4).所以这在 GTK4 中不需要(当你有支持 GTK4 的 java-gnome 时)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM