Anton
Anton

Reputation: 67

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. 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.

Upvotes: 1

Views: 300

Answers (1)

Mohammed Sadiq
Mohammed Sadiq

Reputation: 976

In GTK2 and GTK3, widgets are hidden by default. So you have to explicitly make it visible with gtk_widget_show(). Here, you can do this.entry.show() (and similar, for every widget created).

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.

In GTK4, widgets are visible by default. So this won't be required in GTK4 (when you have java-gnome supporting GTK4).

Upvotes: 1

Related Questions