public class Table extends Container
Table is not a spreadsheet Widget! For that you would need to have (say) a sea of Entry Widgets that were all hooked up to behave the same (notably to pass focus between them appropriately) and which were individually constrained to each be the same size (at least by default), etc. By contrast, Table is for laying out Widgets in a grid but where each child can happily request the size it needs.
To be honest, this Widget is a pain in the ass to use because you have to
manually keep track of which
row,column edges a Widget is to
be constrained by. In most cases you can achieve the same alignment effects
with far greater flexibility by using HBoxes nested in VBoxes and
controlling the size allocations via
Widget.ButtonPressEvent, Widget.ButtonReleaseEvent, Widget.Destroy, Widget.Draw, Widget.EnterNotifyEvent, Widget.FocusInEvent, Widget.FocusOutEvent, Widget.Hide, Widget.KeyPressEvent, Widget.KeyReleaseEvent, Widget.LeaveNotifyEvent, Widget.MapEvent, Widget.MotionNotifyEvent, Widget.PopupMenu, Widget.QueryTooltip, Widget.ScrollEvent, Widget.SizeAllocate, Widget.UnmapEvent, Widget.VisibilityNotifyEvent
|Constructor and Description|
Create a new Table.
|Modifier and Type||Method and Description|
Add a child Widget to this Table.
Change the number of rows and columns in the Table.
Set the (extra) spacing between all columns.
Set the (extra) spacing to be between
Set the (extra) spacing between all rows.
Set the (extra) spacing to be between
activate, addEvents, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, destroy, getAllocatedHeight, getAllocatedWidth, getAllocation, getCanDefault, getCanFocus, getHasFocus, getName, getParent, getPreferredHeightForWidthMinimum, getPreferredHeightForWidthNatural, getPreferredHeightMinimum, getPreferredHeightNatural, getPreferredWidthForHeightMinimum, getPreferredWidthForHeightNatural, getPreferredWidthMinimum, getPreferredWidthNatural, getRequestMode, getRequisition, getSensitive, getStyleContext, getToplevel, getWindow, grabAdd, grabDefault, grabFocus, grabRemove, hide, isSensitive, overrideBackground, overrideColor, overrideFont, queueDraw, queueDrawArea, realize, setAlignHorizontal, setAlignVertical, setCanDefault, setCanFocus, setEvents, setExpandHorizontal, setExpandVertical, setName, setSensitive, setSizeRequest, setTooltipMarkup, setTooltipText, show, showAll
public Table(int rows, int columns, boolean homogeneous)
ncolumns of child Widgets.
true, all cells are sized to that requested by the largest Widget in the Table.
public void attach(Widget child, int leftAttach, int rightAttach, int topAttach, int bottomAttach)
attach()are given appropriate default values.
Each of the parameters refer to the column or row to which the Widget being added will be anchored. To put a Widget at the fourth column from the left, second row down, you would do:
table.attach(child, 3, 4, 1, 2);As alluded to in the class description, this is quite finicky and worse is error prone.
public void attach(Widget child, int leftAttach, int rightAttach, int topAttach, int bottomAttach, AttachOptions xoptions, AttachOptions yoptions, int xpadding, int ypadding)
attach()but has finer layout control for the Widget being added, mostly achieved using the
To define that a Widget shall grow on the x-axis, but keep the size on the y-axis you would do:
table.attach(child, 3, 4, 1, 2, AttachOptions.EXPAND, AttachOptions.SHRINK, 0, 0);
A common problem is that you have Widgets of different sizes (e.g.
labels in a column). If a widget is smaller than the required space
additional padding is added to the sides, so finally the smaller Widget
is centered compared to the larger Widget. To avoid this you a) need to
encapsulate the Widget in an
Alignment Container and b) need to
attach it here using
AttachOptions.FILL, so that instead
of additional space being added to the sides, the
Alignment Container may decide how to distribute it.
The following example left-aligns the child Widget within its cell, while it is vertically centered:
final Alignment aligned; aligned = new Alignment(Alignment.LEFT, Alignment.CENTER, 1.0f, 1.0f, child); table.attach(aligned, 3, 4, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
public void resize(int rows, int columns)
public void setColumnSpacing(int spacing)
public void setColumnSpacing(int column, int spacing)
columnand the one adjacent to it.
public void setRowSpacing(int spacing)
public void setRowSpacing(int row, int spacing)
rowand the one following it.