【问题标题】:Custom Dialog in GTK doesn;t show anythingGTK 中的自定义对话框不显示任何内容
【发布时间】: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)

标签: java gtk


【解决方案1】:

在 GTK2 和 GTK3 中,小部件默认是隐藏的。所以你必须用gtk_widget_show() 明确地让它可见。在这里,您可以执行 this.entry.show() (类似的,对于创建的每个小部件)。

或者,您可以在添加所有小部件后在父容器上执行gtk_widget_show_all()(例如this.showAll()),这将使每个子容器都可见。

在 GTK4 中,小部件默认是可见的。所以这在 GTK4 中是不需要的(当你有支持 GTK4 的 java-gnome 时)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多