java-gnome version 4.0.19

org.gnome.gtk
Class Container

Object
  extended by org.freedesktop.bindings.Pointer
      extended by org.freedesktop.bindings.Proxy
          extended by org.gnome.glib.Object
              extended by org.gnome.gtk.Object
                  extended by org.gnome.gtk.Widget
                      extended by org.gnome.gtk.Container
Direct Known Subclasses:
Bin, Box, Fixed, IconView, Layout, MenuShell, Notebook, Paned, Socket, Table, TextView, Toolbar, ToolItemGroup, ToolPalette, TreeView

public abstract class Container
extends Widget

A Widget that contains at least one, and maybe more, other Widgets. Container is the base of the GTK box packing model; all layouts are composed of Widgets that are packed into other Widgets.

Containers fall into two major categories. They are either:

decorators
Containers which add something around a Widget. Examples include Button (adding the push button aspect to a Widget) and Window (the top level Widget which adds window decorations via the window manager); or
layout
Containers which control the layout of other Widgets within a user interface. Examples include the simplistic Fixed layout tool, the ubiquitous Box subclasses like VBox and HBox, and the more advanced packing mechanisms like Table.

Size Requests and Size Allocation

Containers intermediate in GTK's box packing process. Each Container aggregates the requests from its children during the size request phase, and then later, as actual screen real estate is granted to it, the Container must then divide that space amongst each of its children in the size allocation phase.

For more information about how this works, and on how you can influence it if necessary, see Widget's setSizeRequest(). To get an indication of how much space has been (will be) requested by a child, a Container will also find the getRequisition() method useful. The Actual size granted is available at getAllocation() once the box packing cycle has been carried out.

Since:
4.0.0
Author:
Andrew Cowie

Nested Class Summary
 
Nested classes/interfaces inherited from class org.gnome.gtk.Widget
Widget.ButtonPressEvent, Widget.ButtonReleaseEvent, Widget.EnterNotifyEvent, Widget.ExposeEvent, Widget.FocusInEvent, Widget.FocusOutEvent, Widget.Hide, Widget.KeyPressEvent, Widget.KeyReleaseEvent, Widget.LeaveNotifyEvent, Widget.MapEvent, Widget.MotionNotifyEvent, Widget.PopupMenu, Widget.ScrollEvent, Widget.UnmapEvent, Widget.VisibilityNotifyEvent
 
Nested classes/interfaces inherited from class org.gnome.gtk.Object
Object.Destroy
 
Method Summary
 void add(Widget child)
          Add a child Widget to this Container.
 Widget[] getChildren()
          Get the Widgets that are children of this Container, i.e. the Widgets previously added to the Container.
 void remove(Widget child)
          Remove a Widget from this Container.
 void setBorderWidth(int width)
          Set the amount of padding to put around the outside of this Container, in pixels.
 
Methods inherited from class org.gnome.gtk.Widget
activate, addEvents, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, getAllocation, getCanDefault, getCanFocus, getHasFocus, getName, getParent, getRequisition, getSensitive, getToplevel, getWindow, grabAdd, grabDefault, grabFocus, grabRemove, hide, isSensitive, modifyBackground, modifyBase, modifyFont, modifyText, queueDraw, queueDrawArea, realize, setCanDefault, setCanFocus, setColormap, setEvents, setName, setSensitive, setSizeRequest, setTooltipMarkup, setTooltipText, show, showAll
 
Methods inherited from class org.gnome.gtk.Object
connect, destroy
 
Methods inherited from class org.freedesktop.bindings.Pointer
toString
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

add

public void add(Widget child)
Add a child Widget to this Container. This works for all the various Container types, of course, but most offer more specialized packing methods that allow you to control the positioning of the Widget being added with greater finesse.

Since:
4.0.0

getChildren

public Widget[] getChildren()
Get the Widgets that are children of this Container, i.e. the Widgets previously added to the Container. An array of Widgets isn't always ideal, but you can cast the returned objects to the appropriate Widget subtype should you need to, for example:
 Button button, child;
 Widget[] children;
 
 box.add(button);
 children = box.getChildren();
 
 child = (Button) children[0];
 
In other situations (wondering just what aggregation of Widgets makes up something that was handed to you by Glade, perhaps), instanceof is your friend. Indeed sometimes it's the only way; the box packing composition of GTK elements means that even things you might take for granted as elementary (Button) are in fact more complex (an HBox of an Image and a Label) - and often the only way to find this out is to walk the Widget hierarchy.

Returns:
an array with the Container's child Widgets. The array will be empty (zero length) if the Container hasn't got any children.
Since:
4.0.3

remove

public void remove(Widget child)
Remove a Widget from this Container.

In native GTK, this often results in the destruction of the Widget. In java-gnome, that will only occur once the last Java reference goes out of scope and a garbage collection run occurs. So you can, quite safely, do:

 box1.remove(button);
 box2.add(button);
 
without worrying that that Button is going to evaporate out from under you.

Parameters:
child - A child Widget that is already in the Container, right? If you try to remove a Widget that isn't, don't complain when you get all sorts of errors!
Since:
4.0.2

setBorderWidth

public void setBorderWidth(int width)
Set the amount of padding to put around the outside of this Container, in pixels. This is exterior padding around the outside of the contained Widgets. The default is 0.

Parameters:
width - Although anything under 65535 is a valid value, anyone who thinks they need a border width of sixty thousand pixels is invited to get their head examined.
Since:
4.0.5


java-gnome