Class HyperlinkUtil

java.lang.Object
ca.corbett.extras.io.HyperlinkUtil

public class HyperlinkUtil extends Object
Utility class for hyperlink launching in JREs that support it. Use isBrowsingSupported() to check if the current JRE allows launching hyperlinks. Use the openHyperlink(...) methods to easily launch a given hyperlink in the default browser, or use the many BrowseAction.of() overloads to create an Action that can be used with buttons, menu items, etc.
Since:
swing-extras 2.6
Author:
scorbo2
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    If the current JRE supports browsing, this action will open the given URI in the user's default browser.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Some JREs don't allow launching a hyperlink to open the browser.
    static boolean
    isValidUrl(String urlString)
    Validates that the given String evaluates to a valid URL.
    static void
    If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid).
    static void
    If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid).
    static void
    If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid).
    static void
    If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid).
    static void
    If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid).
    static void
    If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isBrowsingSupported

      public static boolean isBrowsingSupported()
      Some JREs don't allow launching a hyperlink to open the browser.
    • isValidUrl

      public static boolean isValidUrl(String urlString)
      Validates that the given String evaluates to a valid URL.
    • openHyperlink

      public static void openHyperlink(String link)
      If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid). If the JRE doesn't allow such things, then the given link will be copied to the clipboard instead (better than nothing). No message dialog will be shown on failure. If you wish to show a message dialog on failure, use the overload that accepts an owner Component.
    • openHyperlink

      public static void openHyperlink(URL url)
      If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid). If the JRE doesn't allow such things, then the given link will be copied to the clipboard instead (better than nothing). No message dialog will be shown on failure. If you wish to show a message dialog on failure, use the overload that accepts an owner Component.
    • openHyperlink

      public static void openHyperlink(URI uri)
      If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid). If the JRE doesn't allow such things, then the given link will be copied to the clipboard instead (better than nothing). No message dialog will be shown on failure. If you wish to show a message dialog on failure, use the overload that accepts an owner Component.
    • openHyperlink

      public static void openHyperlink(String link, Component owner)
      If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid). If the JRE doesn't allow such things, then the given link will be copied to the clipboard instead (better than nothing). If an owner Component is provided, a message dialog will be shown to inform the user that the link was copied to the clipboard.
    • openHyperlink

      public static void openHyperlink(URL url, Component owner)
      If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid). If the JRE doesn't allow such things, then the given link will be copied to the clipboard instead (better than nothing). If an owner Component is provided, a message dialog will be shown to inform the user that the link was copied to the clipboard.
    • openHyperlink

      public static void openHyperlink(URI uri, Component owner)
      If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid). If the JRE doesn't allow such things, then the given link will be copied to the clipboard instead (better than nothing). If an owner Component is provided, a message dialog will be shown to inform the user that the link was copied to the clipboard.