Class LinkButton

All Implemented Interfaces:
Accessible, Actionable, Buildable, ConstraintTarget, Proxy

@Generated("org.javagi.JavaGI") public class LinkButton extends Button implements Accessible, Actionable, Buildable, ConstraintTarget

A button with a hyperlink.

An example GtkLinkButton

It is useful to show quick links to resources.

A link button is created by calling either LinkButton() or withLabel(String, String). If using the former, the URI you pass to the constructor is used as a label for the widget.

The URI bound to a GtkLinkButton can be set specifically using setUri(String).

By default, GtkLinkButton calls FileLauncher.launch(Window, Cancellable, AsyncReadyCallback) when the button is clicked. This behaviour can be overridden by connecting to the Gtk.LinkButton::activate-link signal and returning true from the signal handler.

Shortcuts and Gestures

GtkLinkButton supports the following keyboard shortcuts:

  • Shift+F10 or Menu opens the context menu.

Actions

GtkLinkButton defines a set of built-in actions:

  • clipboard.copy copies the url to the clipboard.
  • menu.popup opens the context menu.

CSS nodes

GtkLinkButton has a single CSS node with name button. To differentiate it from a plain GtkButton, it gets the .link style class.

Accessibility

GtkLinkButton uses the Gtk.AccessibleRole.link role.

  • Constructor Details

    • LinkButton

      public LinkButton(MemorySegment address)
      Create a LinkButton instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • LinkButton

      public LinkButton(String uri)
      Creates a new GtkLinkButton with the URI as its text.
      Parameters:
      uri - a valid URI
    • LinkButton

      public LinkButton()
      Create a new LinkButton.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the LinkButton class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected LinkButton asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Button
      Returns:
      the instance as if it were its parent type
    • withLabel

      public static LinkButton withLabel(String uri, @Nullable String label)
      Creates a new GtkLinkButton containing a label.
      Parameters:
      uri - a valid URI
      label - the text of the button
      Returns:
      a new link button widget.
    • getUri

      public String getUri()
      Retrieves the URI of the GtkLinkButton.
      Returns:
      a valid URI. The returned string is owned by the link button and should not be modified or freed.
    • getVisited

      public boolean getVisited()

      Retrieves the “visited” state of the GtkLinkButton.

      The button becomes visited when it is clicked. If the URI is changed on the button, the “visited” state is unset again.

      The state may also be changed using setVisited(boolean).

      Returns:
      true if the link has been visited, false otherwise
    • setUri

      public void setUri(String uri)

      Sets uri as the URI where the GtkLinkButton points.

      As a side-effect this unsets the “visited” state of the button.

      Parameters:
      uri - a valid URI
    • setVisited

      public void setVisited(boolean visited)

      Sets the “visited” state of the GtkLinkButton.

      See getVisited() for more details.

      Parameters:
      visited - the new “visited” state
    • onActivateLink

      Emitted each time the GtkLinkButton is clicked.

      The default handler will call FileLauncher.launch(Window, Cancellable, AsyncReadyCallback) with the URI stored inside the Gtk.LinkButton:uri property.

      To override the default behavior, you can connect to the ::activate-link signal and stop the propagation of the signal by returning true from your handler.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitActivateLink

      public boolean emitActivateLink()
      Emits the "activate-link" signal. See onActivateLink(LinkButton.ActivateLinkCallback).
    • builder

      public static LinkButton.Builder<? extends LinkButton.Builder> builder()
      A LinkButton.Builder object constructs a LinkButton with the specified properties. Use the various set...() methods to set properties, and finish construction with LinkButton.Builder.build().
      Returns:
      the builder object