Class Picture
- All Implemented Interfaces:
Proxy
,Accessible
,Buildable
,ConstraintTarget
GtkPicture
widget displays a GdkPaintable
.
Many convenience functions are provided to make pictures simple to use. For example, if you want to load an image from a file, and then display it, there’s a convenience function to do this:
GtkWidget *widget = gtk_picture_new_for_filename ("myfile.png");
If the file isn’t loaded successfully, the picture will contain a
“broken image” icon similar to that used in many web browsers.
If you want to handle errors in loading the file yourself,
for example by displaying an error message, then load the image with
Texture.fromFile(org.gnome.gio.File)
, then create the GtkPicture
with
forPaintable(org.gnome.gdk.Paintable)
.
Sometimes an application will want to avoid depending on external data
files, such as image files. See the documentation of GResource
for details.
In this case, forResource(java.lang.String)
and
setResource(java.lang.String)
should be used.
GtkPicture
displays an image at its natural size. See Image
if you want to display a fixed-size image, such as an icon.
Sizing the paintable
You can influence how the paintable is displayed inside the GtkPicture
by changing Gtk.Picture:content-fit
. See Gtk.ContentFit
for details. Gtk.Picture:can-shrink
can be unset to make sure
that paintables are never made smaller than their ideal size - but
be careful if you do not know the size of the paintable in use (like
when displaying user-loaded images). This can easily cause the picture to
grow larger than the screen. And Gtk.Widget:halign
and
Gtk.Widget:valign
can be used to make sure the paintable doesn't
fill all available space but is instead displayed at its original size.
CSS nodes
GtkPicture
has a single CSS node with the name picture
.
Accessibility
GtkPicture
uses the GTK_ACCESSIBLE_ROLE_IMG
role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Picture.Builder<B extends Picture.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested 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.WidgetClass, Widget.WidgetImpl
Nested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClass
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.AccessibleImpl, Accessible.AccessibleInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.BuildableIface, Buildable.BuildableImpl
Nested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTargetImpl, ConstraintTarget.ConstraintTargetInterface
-
Constructor Summary
ConstructorDescriptionPicture()
Creates a new emptyGtkPicture
widget.Picture
(MemorySegment address) Create a Picture proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Picture
asParent()
Returns this instance as if it were its parent type.static Picture.Builder
<? extends Picture.Builder> builder()
APicture.Builder
object constructs aPicture
with the specified properties.static Picture
Creates a newGtkPicture
displaying the givenfile
.static Picture
forFilename
(@Nullable String filename) Creates a newGtkPicture
displaying the filefilename
.static Picture
forPaintable
(@Nullable Paintable paintable) Creates a newGtkPicture
displayingpaintable
.static Picture
Deprecated.static Picture
forResource
(@Nullable String resourcePath) Creates a newGtkPicture
displaying the resource atresourcePath
.Gets the alternative textual description of the picture.boolean
Returns whether theGtkPicture
respects its contents size.Returns the fit mode for the content of theGtkPicture
.getFile()
Gets theGFile
currently displayed if this Picture is displaying a file.boolean
Deprecated.UsegetContentFit()
instead.Gets theGdkPaintable
being displayed by theGtkPicture
.static Type
getType()
Get the GType of the Picture classvoid
setAlternativeText
(@Nullable String alternativeText) Sets an alternative textual description for the picture contents.void
setCanShrink
(boolean canShrink) If set totrue
, the this Picture can be made smaller than its contents.void
setContentFit
(ContentFit contentFit) Sets how the content should be resized to fit theGtkPicture
.void
Makes this Picture load and displayfile
.void
setFilename
(@Nullable String filename) Makes this Picture load and display the givenfilename
.void
setKeepAspectRatio
(boolean keepAspectRatio) Deprecated.UsesetContentFit(org.gnome.gtk.ContentFit)
instead.void
setPaintable
(@Nullable Paintable paintable) Makes this Picture display the givenpaintable
.void
Deprecated.UsesetPaintable(org.gnome.gdk.Paintable)
insteadvoid
setResource
(@Nullable String resourcePath) Makes this Picture load and display the resource at the givenresourcePath
.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, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getMemoryLayout, 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, 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, unsetStateFlags
Methods 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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updateProperty, updateRelation, updateState
Methods inherited from interface org.gnome.gtk.Buildable
getBuildableId
-
Constructor Details
-
Picture
Create a Picture proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Picture
public Picture()Creates a new emptyGtkPicture
widget.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, 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. -
forFile
Creates a newGtkPicture
displaying the givenfile
.If the file isn’t found or can’t be loaded, the resulting
GtkPicture
is empty.If you need to detect failures to load the file, use
Texture.fromFile(org.gnome.gio.File)
to load the file yourself, then create theGtkPicture
from the texture.- Parameters:
file
- aGFile
- Returns:
- a new
GtkPicture
-
forFilename
Creates a newGtkPicture
displaying the filefilename
.This is a utility function that calls
forFile(org.gnome.gio.File)
. See that function for details.- Parameters:
filename
- a filename- Returns:
- a new
GtkPicture
-
forPaintable
-
forPixbuf
Deprecated.Creates a newGtkPicture
displayingpixbuf
.This is a utility function that calls
forPaintable(org.gnome.gdk.Paintable)
, See that function for details.The pixbuf must not be modified after passing it to this function.
- Parameters:
pixbuf
- aGdkPixbuf
- Returns:
- a new
GtkPicture
-
forResource
Creates a newGtkPicture
displaying the resource atresourcePath
.This is a utility function that calls
forFile(org.gnome.gio.File)
. See that function for details.- Parameters:
resourcePath
- resource path to play back- Returns:
- a new
GtkPicture
-
getAlternativeText
Gets the alternative textual description of the picture.The returned string will be
null
if the picture cannot be described textually.- Returns:
- the alternative textual description of this Picture.
-
getCanShrink
public boolean getCanShrink()Returns whether theGtkPicture
respects its contents size.- Returns:
true
if the picture can be made smaller than its contents
-
getContentFit
Returns the fit mode for the content of theGtkPicture
.See
Gtk.ContentFit
for details.- Returns:
- the content fit mode
-
getFile
Gets theGFile
currently displayed if this Picture is displaying a file.If this Picture is not displaying a file, for example when
setPaintable(org.gnome.gdk.Paintable)
was used, thennull
is returned.- Returns:
- The
GFile
displayed by this Picture.
-
getKeepAspectRatio
Deprecated.UsegetContentFit()
instead. This will now returnFALSE
only ifGtk.Picture:content-fit
isGTK_CONTENT_FIT_FILL
. ReturnsTRUE
otherwise.Returns whether theGtkPicture
preserves its contents aspect ratio.- Returns:
true
if the self tries to keep the contents' aspect ratio
-
getPaintable
Gets theGdkPaintable
being displayed by theGtkPicture
.- Returns:
- the displayed paintable
-
setAlternativeText
Sets an alternative textual description for the picture contents.It is equivalent to the "alt" attribute for images on websites.
This text will be made available to accessibility tools.
If the picture cannot be described textually, set this property to
null
.- Parameters:
alternativeText
- a textual description of the contents
-
setCanShrink
public void setCanShrink(boolean canShrink) If set totrue
, the this Picture can be made smaller than its contents.The contents will then be scaled down when rendering.
If you want to still force a minimum size manually, consider using
Widget.setSizeRequest(int, int)
.Also of note is that a similar function for growing does not exist because the grow behavior can be controlled via
Widget.setHalign(org.gnome.gtk.Align)
andWidget.setValign(org.gnome.gtk.Align)
.- Parameters:
canShrink
- if this Picture can be made smaller than its contents
-
setContentFit
Sets how the content should be resized to fit theGtkPicture
.See
Gtk.ContentFit
for details.- Parameters:
contentFit
- the content fit mode
-
setFile
Makes this Picture load and displayfile
.See
forFile(org.gnome.gio.File)
for details.- Parameters:
file
- aGFile
-
setFilename
Makes this Picture load and display the givenfilename
.This is a utility function that calls
setFile(org.gnome.gio.File)
.- Parameters:
filename
- the filename to play
-
setKeepAspectRatio
Deprecated.UsesetContentFit(org.gnome.gtk.ContentFit)
instead. If still used, this method will always set theGtk.Picture:content-fit
property toGTK_CONTENT_FIT_CONTAIN
ifkeepAspectRatio
is true, otherwise it will set it toGTK_CONTENT_FIT_FILL
.If set totrue
, the this Picture will render its contents according to their aspect ratio.That means that empty space may show up at the top/bottom or left/right of this Picture.
If set to
false
or if the contents provide no aspect ratio, the contents will be stretched over the picture's whole area.- Parameters:
keepAspectRatio
- whether to keep aspect ratio
-
setPaintable
Makes this Picture display the givenpaintable
.If
paintable
isnull
, nothing will be displayed.See
forPaintable(org.gnome.gdk.Paintable)
for details.- Parameters:
paintable
- aGdkPaintable
-
setPixbuf
Deprecated.UsesetPaintable(org.gnome.gdk.Paintable)
insteadSets aGtkPicture
to show aGdkPixbuf
.See
forPixbuf(org.gnome.gdkpixbuf.Pixbuf)
for details.This is a utility function that calls
setPaintable(org.gnome.gdk.Paintable)
.- Parameters:
pixbuf
- aGdkPixbuf
-
setResource
Makes this Picture load and display the resource at the givenresourcePath
.This is a utility function that calls
setFile(org.gnome.gio.File)
.- Parameters:
resourcePath
- the resource to set
-
builder
APicture.Builder
object constructs aPicture
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withPicture.Builder.build()
.
-
forPaintable(org.gnome.gdk.Paintable)
andTexture.forPixbuf(org.gnome.gdkpixbuf.Pixbuf)
instead