Java-GNOME 2.10 GNOME Tutorial
<<< Previous |  | Next >>>

# The Widgets

It is probably about time to start talking about the widgets that are available in Java-GNOME. There are so many widgets that I will not be able to cover them all. Instead I will just focus on a few of the most used and most complex. A good resource to learn about other widgets available in GTK is the GTK tutorial which is on the gtk web site. Although it discusses the C implimentation it is very useful for Java-GNOME developers since there are many similarities.

# Gtk Entry

The Entry widget in GTK is a sinle line text entry widget. A fairly large set of key bindings are supported by default. If the entered text is longer than the allocation of the widget, the widget will scroll so that the cursor position is visible. It fires three EditableEvent events; changed, delete_text, and insert_text.

Below is a very brief example of how you can create an Entry widget.

Example 1. EntryDemo.java - Gtk Entry

    import org.gnu.gtk.Entry;
    import org.gnu.gtk.Gtk;
    import org.gnu.gtk.HBox;
    import org.gnu.gtk.Widget;
    import org.gnu.gtk.Window;
    import org.gnu.gtk.WindowType;
    import org.gnu.gtk.event.LifeCycleEvent;
    import org.gnu.gtk.event.LifeCycleListener;

    public class EntryDemo {

    	public static Widget createEntryWidget(){
    		HBox b = new HBox(true,0);
    		Entry entry = new Entry();
    		entry.setText("Entry widget demo.");
    		entry.setVisible(true);
    		b.add(entry);
    		return b;
    	}

    	public static void main(String[] args) {
    		Gtk.init(args);
    		Window w = new Window(WindowType.TOPLEVEL);
    		w.addListener(new LifeCycleListener() {
    			public void lifeCycleEvent(LifeCycleEvent event) {}
    			public boolean lifeCycleQuery(LifeCycleEvent event) {
    				Gtk.mainQuit();
    				return false;
    			}
    		});
    		w.setDefaultSize(200,30);
    		w.setBorderWidth(5);
    		w.setTitle("The Java-Gnome team");
    		w.add(createEntryWidget());
    		w.showAll();
    		Gtk.main();
    	}
    }

<<< Previous | Home | Next >>>
Url |  | CheckButton