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 SizeGroup
s.
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 |
---|
Table(int rows,
int columns,
boolean homogeneous)
Create a new Table.
|
Modifier and Type | Method and Description |
---|---|
void |
attach(Widget child,
int leftAttach,
int rightAttach,
int topAttach,
int bottomAttach)
Add a child Widget to this Table.
|
void |
attach(Widget child,
int leftAttach,
int rightAttach,
int topAttach,
int bottomAttach,
AttachOptions xoptions,
AttachOptions yoptions,
int xpadding,
int ypadding)
Like
attach() but has finer
layout control for the Widget being added, mostly achieved using the
AttachOptions . |
void |
resize(int rows,
int columns)
Change the number of rows and columns in the Table.
|
void |
setColumnSpacing(int spacing)
Set the (extra) spacing between all columns.
|
void |
setColumnSpacing(int column,
int spacing)
Set the (extra) spacing to be between
column and the one
adjacent to it. |
void |
setRowSpacing(int spacing)
Set the (extra) spacing between all rows.
|
void |
setRowSpacing(int row,
int spacing)
Set the (extra) spacing to be between
row and the one
following it. |
add, getChildren, remove, setBorderWidth
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)
n
rows of n
columns of child Widgets.homogeneous
- If 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
AttachOptions
.
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)
setColumnSpacing()
.public void setColumnSpacing(int column, int spacing)
column
and the one
adjacent to it.public void setRowSpacing(int spacing)
setRowSpacing(int,int)
.public void setRowSpacing(int row, int spacing)
row
and the one
following it.