Package ca.corbett.extras.io
Class HyperlinkUtil
java.lang.Object
ca.corbett.extras.io.HyperlinkUtil
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 ClassesModifier and TypeClassDescriptionstatic classIf the current JRE supports browsing, this action will open the given URI in the user's default browser. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanSome JREs don't allow launching a hyperlink to open the browser.static booleanisValidUrl(String urlString) Validates that the given String evaluates to a valid URL.static voidopenHyperlink(String link) If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid).static voidopenHyperlink(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).static voidopenHyperlink(URI uri) If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid).static voidopenHyperlink(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).static voidopenHyperlink(URL url) If hyperlink launching is supported, will open the user's default browser to the given link (assuming the link is valid).static voidopenHyperlink(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).
-
Method Details
-
isBrowsingSupported
public static boolean isBrowsingSupported()Some JREs don't allow launching a hyperlink to open the browser. -
isValidUrl
Validates that the given String evaluates to a valid URL. -
openHyperlink
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
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
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
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
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
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.
-