Class Grid
- All Implemented Interfaces:
Accessible,Buildable,ConstraintTarget,Orientable,Proxy
It supports arbitrary positions and horizontal/vertical spans.
Children are added using attach(org.gnome.gtk.Widget, int, int, int, int). They can span multiple
rows or columns. It is also possible to add a child next to an existing
child, using attachNextTo(org.gnome.gtk.Widget, org.gnome.gtk.Widget, org.gnome.gtk.PositionType, int, int). To remove a child from the
grid, use remove(org.gnome.gtk.Widget).
The behaviour of GtkGrid when several children occupy the same grid
cell is undefined.
GtkGrid as GtkBuildable
Every child in a GtkGrid has access to a custom Buildable
element, called <layout>. It can by used to specify a position in the
grid and optionally spans. All properties that can be used in the <layout>
element are implemented by GridLayoutChild.
It is implemented by GtkWidget using LayoutManager.
To showcase it, here is a simple example:
<object class="GtkGrid" id="my_grid">
<child>
<object class="GtkButton" id="button1">
<property name="label">Button 1</property>
<layout>
<property name="column">0</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label">Button 2</property>
<layout>
<property name="column">1</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="button3">
<property name="label">Button 3</property>
<layout>
<property name="column">2</property>
<property name="row">0</property>
<property name="row-span">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="button4">
<property name="label">Button 4</property>
<layout>
<property name="column">0</property>
<property name="row">1</property>
<property name="column-span">2</property>
</layout>
</object>
</child>
</object>
It organizes the first two buttons side-by-side in one cell each.
The third button is in the last column but spans across two rows.
This is defined by the row-span property. The last button is
located in the second row and spans across two columns, which is
defined by the column-span property.
CSS nodes
GtkGrid uses a single CSS node with name grid.
Accessibility
Until GTK 4.10, GtkGrid used the Gtk.AccessibleRole.group role.
Starting from GTK 4.12, GtkGrid uses the Gtk.AccessibleRole.generic role.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classGrid.Builder<B extends Grid.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class org.gnome.gtk.Widget
Widget.DestroyCallback, Widget.DirectionChangedCallback, Widget.HideCallback, Widget.KeynavFailedCallback, Widget.MapCallback, Widget.MnemonicActivateCallback, Widget.MoveFocusCallback, Widget.QueryTooltipCallback, Widget.RealizeCallback, Widget.ShowCallback, Widget.StateFlagsChangedCallback, Widget.UnmapCallback, Widget.UnrealizeCallback, Widget.Widget$Impl, Widget.WidgetClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.Accessible$Impl, Accessible.AccessibleInterfaceNested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.Buildable$Impl, Buildable.BuildableIfaceNested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTarget$Impl, ConstraintTarget.ConstraintTargetInterfaceNested classes/interfaces inherited from interface org.gnome.gtk.Orientable
Orientable.Orientable$Impl, Orientable.OrientableIface -
Constructor Summary
ConstructorsConstructorDescriptionGrid()Creates a new Grid.Grid(MemorySegment address) Create a Grid proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected GridasParent()Returns this instance as if it were its parent type.voidAdds a widget to the grid.voidattachNextTo(Widget child, @Nullable Widget sibling, PositionType side, int width, int height) Adds a widget to the grid.static Grid.Builder<? extends Grid.Builder> builder()AGrid.Builderobject constructs aGridwith the specified properties.intReturns which row defines the global baseline ofgrid.@Nullable WidgetgetChildAt(int column, int row) Gets the child of this Grid whose area covers the grid cell atcolumn,row.booleanReturns whether all columns of this Grid have the same width.intReturns the amount of space between the columns ofgrid.static MemoryLayoutThe memory layout of the native struct.getRowBaselinePosition(int row) Returns the baseline position ofrow.booleanReturns whether all rows of this Grid have the same height.intReturns the amount of space between the rows ofgrid.static @Nullable TypegetType()Get the GType of the Grid classvoidinsertColumn(int position) Inserts a column at the specified position.voidinsertNextTo(Widget sibling, PositionType side) Inserts a row or column at the specified position.voidinsertRow(int position) Inserts a row at the specified position.voidqueryChild(Widget child, @Nullable Out<Integer> column, @Nullable Out<Integer> row, @Nullable Out<Integer> width, @Nullable Out<Integer> height) Queries the attach points and spans ofchildinside the givenGtkGrid.voidRemoves a child fromgrid.voidremoveColumn(int position) Removes a column from the grid.voidremoveRow(int position) Removes a row from the grid.voidsetBaselineRow(int row) Sets which row defines the global baseline for the entire grid.voidsetColumnHomogeneous(boolean homogeneous) Sets whether all columns of this Grid will have the same width.voidsetColumnSpacing(int spacing) Sets the amount of space between columns ofgrid.voidsetRowBaselinePosition(int row, BaselinePosition pos) Sets how the baseline should be positioned onrowof the grid, in case that row is assigned more space than is requested.voidsetRowHomogeneous(boolean homogeneous) Sets whether all rows of this Grid will have the same height.voidsetRowSpacing(int spacing) Sets the amount of space between rows ofgrid.Methods inherited from class org.gnome.gtk.Widget
actionSetEnabled, activateActionIfExists, activateDefault, activateWidget, addController, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, cssChanged, directionChanged, disposeTemplate, dragCheckThreshold, emitDestroy, emitDirectionChanged, emitHide, emitKeynavFailed, emitMap, emitMnemonicActivate, emitMoveFocus, emitQueryTooltip, emitRealize, emitShow, emitStateFlagsChanged, emitUnmap, emitUnrealize, errorBell, focus, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getBaseline, getCanFocus, getCanTarget, getChildVisible, getClipboard, getColor, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getLimitEvents, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, moveFocus, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, pick, queryTooltip, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeMnemonicLabel, removeTickCallback, root, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setLimitEvents, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setStateFlags, setTooltipMarkup, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, sizeAllocate, snapshot, snapshotChild, stateFlagsChanged, systemSettingChanged, translateCoordinates, triggerTooltipQuery, unmap, unparent, unrealize, unroot, unsetStateFlags, unsetStateFlagsMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updatePlatformState, updateProperty, updateRelation, updateStateMethods inherited from interface org.gnome.gtk.Buildable
getBuildableIdMethods inherited from interface org.gnome.gtk.Orientable
getOrientation, setOrientation
-
Constructor Details
-
Grid
Create a Grid proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Grid
public Grid()Creates a new Grid.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
attach
Adds a widget to the grid.The position of
childis determined bycolumnandrow.The number of “cells” thatchildwill occupy is determined bywidthandheight.- Parameters:
child- the widget to addcolumn- the column number to attach the left side ofchildtorow- the row number to attach the top side ofchildtowidth- the number of columns thatchildwill spanheight- the number of rows thatchildwill span
-
attachNextTo
public void attachNextTo(Widget child, @Nullable Widget sibling, PositionType side, int width, int height) Adds a widget to the grid.The widget is placed next to
sibling,on the side determined byside.Whensiblingisnull, the widget is placed in row (for left or right placement) or column 0 (for top or bottom placement), at the end indicated byside.Attaching widgets labeled
[1],[2],[3]with@sibling == %NULLand@side == %GTK_POS_LEFTyields a layout of[3][2][1].- Parameters:
child- the widget to addsibling- the child of this Grid thatchildwill be placed next to, ornullto placechildat the beginning or endside- the side ofsiblingthatchildis positioned next towidth- the number of columns thatchildwill spanheight- the number of rows thatchildwill span
-
getBaselineRow
public int getBaselineRow()Returns which row defines the global baseline ofgrid.- Returns:
- the row index defining the global baseline
-
getChildAt
Gets the child of this Grid whose area covers the grid cell atcolumn,row.- Parameters:
column- the left edge of the cellrow- the top edge of the cell- Returns:
- the child at the given position
-
getColumnHomogeneous
public boolean getColumnHomogeneous()Returns whether all columns of this Grid have the same width.- Returns:
- whether all columns of this Grid have the same width.
-
getColumnSpacing
public int getColumnSpacing()Returns the amount of space between the columns ofgrid.- Returns:
- the column spacing of this Grid
-
getRowBaselinePosition
Returns the baseline position ofrow.See
setRowBaselinePosition(int, org.gnome.gtk.BaselinePosition).- Parameters:
row- a row index- Returns:
- the baseline position of
row
-
getRowHomogeneous
public boolean getRowHomogeneous()Returns whether all rows of this Grid have the same height.- Returns:
- whether all rows of this Grid have the same height.
-
getRowSpacing
public int getRowSpacing()Returns the amount of space between the rows ofgrid.- Returns:
- the row spacing of this Grid
-
insertColumn
public void insertColumn(int position) Inserts a column at the specified position.Children which are attached at or to the right of this position are moved one column to the right. Children which span across this position are grown to span the new column.
- Parameters:
position- the position to insert the column at
-
insertNextTo
Inserts a row or column at the specified position.The new row or column is placed next to
sibling,on the side determined byside.IfsideisPositionType.TOPorPositionType.BOTTOM, a row is inserted. IfsideisPositionType.LEFTofPositionType.RIGHT, a column is inserted.- Parameters:
sibling- the child of this Grid that the new row or column will be placed next toside- the side ofsiblingthatchildis positioned next to
-
insertRow
public void insertRow(int position) Inserts a row at the specified position.Children which are attached at or below this position are moved one row down. Children which span across this position are grown to span the new row.
- Parameters:
position- the position to insert the row at
-
queryChild
public void queryChild(Widget child, @Nullable Out<Integer> column, @Nullable Out<Integer> row, @Nullable Out<Integer> width, @Nullable Out<Integer> height) Queries the attach points and spans ofchildinside the givenGtkGrid.- Parameters:
child- aGtkWidgetchild of this Gridcolumn- the column used to attach the left side ofchildrow- the row used to attach the top side ofchildwidth- the number of columnschildspansheight- the number of rowschildspans
-
remove
Removes a child fromgrid.The child must have been added with
attach(org.gnome.gtk.Widget, int, int, int, int)orattachNextTo(org.gnome.gtk.Widget, org.gnome.gtk.Widget, org.gnome.gtk.PositionType, int, int).- Parameters:
child- the child widget to remove
-
removeColumn
public void removeColumn(int position) Removes a column from the grid.Children that are placed in this column are removed, spanning children that overlap this column have their width reduced by one, and children after the column are moved to the left.
- Parameters:
position- the position of the column to remove
-
removeRow
public void removeRow(int position) Removes a row from the grid.Children that are placed in this row are removed, spanning children that overlap this row have their height reduced by one, and children below the row are moved up.
- Parameters:
position- the position of the row to remove
-
setBaselineRow
public void setBaselineRow(int row) Sets which row defines the global baseline for the entire grid.Each row in the grid can have its own local baseline, but only one of those is global, meaning it will be the baseline in the parent of the
grid.- Parameters:
row- the row index
-
setColumnHomogeneous
public void setColumnHomogeneous(boolean homogeneous) Sets whether all columns of this Grid will have the same width.- Parameters:
homogeneous-trueto make columns homogeneous
-
setColumnSpacing
public void setColumnSpacing(int spacing) Sets the amount of space between columns ofgrid.- Parameters:
spacing- the amount of space to insert between columns
-
setRowBaselinePosition
Sets how the baseline should be positioned onrowof the grid, in case that row is assigned more space than is requested.The default baseline position is
BaselinePosition.CENTER.- Parameters:
row- a row indexpos- aGtkBaselinePosition
-
setRowHomogeneous
public void setRowHomogeneous(boolean homogeneous) Sets whether all rows of this Grid will have the same height.- Parameters:
homogeneous-trueto make rows homogeneous
-
setRowSpacing
public void setRowSpacing(int spacing) Sets the amount of space between rows ofgrid.- Parameters:
spacing- the amount of space to insert between rows
-
builder
AGrid.Builderobject constructs aGridwith the specified properties. Use the variousset...()methods to set properties, and finish construction withGrid.Builder.build().- Returns:
- the builder object
-