Re: [Java-gnome-developer] Grabbing default in a subclass of Dialog
Brought to you by:
afcowie
From: Richard S. <ri...@r-...> - 2010-08-11 13:02:21
|
On 11/08/10 01:31, Andrew Cowie wrote: > I've added coverage for setDefaultReponse() to Dialog, and merged it > to 'mainline'. It'll be in java-gnome 4.0.17 Thanks Andrew, I've grabbed the mainline source and compiled it, but I still can't get it to work. I'm definitely using the 4.0.17-dev version. Sorry for the long and untidy code snippet but here's a test case that doesn't work for me: package test; import org.freedesktop.bindings.Version; import org.gnome.gdk.Event; import org.gnome.gtk.*; public class TestDefaultButton { public TestDefaultButton() { // Create a main window Window window = new Window(); window.setTitle("Default Button (Java-Gnome v" + Version.getVersion() + ")"); window.setDefaultSize(600, 400); // Add a button to the main window that launches a dialog Button showDialogButton = new Button("Show Dialog"); HBox hbox = new HBox(true, 0); hbox.packStart(showDialogButton, false, false, 0); VBox vbox = new VBox(true, 0); vbox.packStart(hbox, false, false, 0); window.add(vbox); // Create a dialog final Dialog dialog = new Dialog("Dialog", window, false); final Entry entry = new Entry(); // Add a label and text entry to the dialog HBox hbox1 = new HBox(false, 5); hbox1.packStart(new Label("Enter text:"), false, false, 10); hbox1.packStart(entry, true, true, 5); VBox vbox1 = new VBox(true, 0); vbox1.packStart(hbox1, true, true, 10); dialog.add(vbox1); // Add close and apply buttons, making apply the default final Button defaultButton = new Button(Stock.APPLY); defaultButton.setCanDefault(true); dialog.addButton(Stock.CLOSE, ResponseType.CLOSE); dialog.addButton(defaultButton, ResponseType.APPLY); dialog.setDefaultResponse(ResponseType.APPLY); // Connect the handler that shows the dialog showDialogButton.connect(new Button.Clicked() { public void onClicked(Button source) { entry.setText(""); entry.grabFocus(); defaultButton.grabDefault(); dialog.showAll(); } }); // Connect a window delete handler to the main window window.connect(new Window.DeleteEvent() { public boolean onDeleteEvent(Widget source, Event event) { Gtk.mainQuit(); return false; } }); // Connect the dialog response to print the content of the entry on // apply, // or to close the dialog on close dialog.connect(new Dialog.Response() { public void onResponse(Dialog source, ResponseType response) { if (response == ResponseType.APPLY) { System.out.println(entry.getText()); } else { source.hide(); } } }); // Show the main window window.showAll(); } public static void main(String... args) { Gtk.init(args); new TestDefaultButton(); Gtk.main(); } } -- Regards, Richard |