Class SwingUtil

java.lang.Object
chemaxon.marvin.util.SwingUtil
All Implemented Interfaces:
Serializable

@PublicApi public class SwingUtil extends Object implements Serializable
Swing utility functions.
Since:
Marvin 3.3.1, 01/15/2004
See Also:
  • Constructor Details

    • SwingUtil

      public SwingUtil()
  • Method Details

    • initInApplet

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public static void initInApplet()
      Deprecated, for removal: This API element is subject to removal in a future version.
      does nothing.
    • getCommandKeyStroke

      public static KeyStroke getCommandKeyStroke(int key)
      Gets the command keystroke preferred on the current platform. Ctrl+key on Linux and Windows, Command+key on Mac.
      Parameters:
      key - the key
      Returns:
      keystroke for the specified key and meta (for Mac) or control (for other platforms)
    • createMenuItem

      public static JMenuItem createMenuItem(ResourceBundle rc, String key, Class<?> what, boolean mnemo)
      Creates a menu item with a label specified as a resource. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      rc - the resources
      key - name of the label resource
      what - menu item class
      mnemo - use mnemonic or not
      Returns:
      the menu
      Since:
      Marvin 4.1, 11/10/2005
    • createMenuItem

      public static JMenuItem createMenuItem(ResourceBundle rc, String key, boolean mnemo)
      Creates a menu with a label specified as a resource. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      rc - the resources
      key - name of the label resource
      mnemo - set the mnemonic or not
      Returns:
      the menu item
      Since:
      Marvin 4.1, 11/10/2005
    • createMenuItem

      public static JMenuItem createMenuItem(ResourceBundle rc, String key)
      Creates a menu with a label specified as a resource. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      rc - the resources
      key - name of the label resource
      Returns:
      the menu item
      Since:
      Marvin 4.1, 11/10/2005
    • createMenu

      public static JMenu createMenu(ResourceBundle rc, String key)
      Utility method to create a menu with a label specified as a resource. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      rc - the resources
      key - name of the label resource
      Returns:
      the menu
    • createMenu

      public static JMenu createMenu(ResourceBundle rc, String key, boolean mnemo)
      Creates a menu with a label specified as a resource. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      rc - the resources
      key - name of the label resource
      mnemo - set the mnemonic or not
      Returns:
      the menu
      Since:
      Marvin 4.1, 11/10/2005
    • initButton

      public static void initButton(AbstractButton b, ResourceBundle rc, String key)
      Utility method to initialize a button from information in a resource. If the resource string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      b - the button
      rc - the resources
      key - name of the resource
    • initButton

      public static void initButton(AbstractButton b, ResourceBundle rc, String key, boolean mnemo)
      Utility method to initialize a button from information in a resource. If the resource string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      b - the button
      rc - the resources
      key - name of the resource
      mnemo - set the mnemonic or not
    • initAction

      public static void initAction(Action action, ResourceBundle rc, String key, KeyStroke accel)
      Initializes an action from information in a resource. If the resource string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      action - the action
      rc - the resources
      key - name of the resource
      accel - the accelerator or null
    • initCtrlShortcutForMac

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public static void initCtrlShortcutForMac(JMenuItem mi)
      Deprecated, for removal: This API element is subject to removal in a future version.
      does nothing.
    • decorateSubPanel

      public static void decorateSubPanel(JPanel panel, String title)
      Creates border and title for a panel.
      Parameters:
      title - the panel title
      Since:
      Marvin 4.1, 11/10/2005
    • createSubPanel

      public static JPanel createSubPanel(String title)
      Creates a sub-panel with a title.
      Parameters:
      title - the panel title
      Returns:
      the panel
      Since:
      Marvin 4.1, 11/10/2005
      See Also:
    • createTopLeftConstraints

      public static GridBagConstraints createTopLeftConstraints()
      Creates GridBagConstraints for the top left component.
      Returns:
      the constraints
      Since:
      Marvin 4.1, 11/10/2005
    • createMessagePane

      public static JEditorPane createMessagePane(String text)
      Creates a message pane with HTML text content. HTML links are handled, referred pages are displayed in the default browser.
      Parameters:
      text - the content, may contain HTML links
      Returns:
      the message pane
    • setDefaultFont

      public static void setDefaultFont(JEditorPane editorPane)
      Sets the SWING default font in the JEditorPane. This is necessary because originally the font is read from a style sheet. This method adds a CSS rule to force body tags to use the default label font instead of the value in javax.swing.text.html.default.css. Code is copied from: http://explodingpixels.wordpress.com/2008/10/28/make-jeditorpane-use-the-system-font/
      Parameters:
      editorPane - the JEditorPane
    • addHyperlinkListener

      public static void addHyperlinkListener(JEditorPane editorPane)
      Adds HTML link handling to an editor pane. The referred content will be displayed in the default browser.
      Parameters:
      editorPane - the JEditorPane
    • invokeLater

      public static <T> FutureTask<T> invokeLater(Callable<T> callable)
      Calls SwingUtilities.invokeLater() for a Callable by wrapping it into a FutureTask object. Written by Karl Schaefer. Source: http://weblogs.java.net/blog/kschaefe/archive/2010/11/15/returns-values-swingutilitiesinvoke
      Parameters:
      callable - the Callable object to be invoked on the event dispatch thread
      Returns:
      the wrapper FutureTask
    • invokeAndWait

      public static <T> T invokeAndWait(Callable<T> callable) throws InterruptedException, InvocationTargetException
      Calls SwingUtilities.invokeLater() for a Callable by wrapping it into a FutureTask object, blocks until it is finished and returns the result (calling FutureTask.get()). Written by Karl Schaefer. Source: http://weblogs.java.net/blog/kschaefe/archive/2010/11/15/returns-values-swingutilitiesinvoke
      Parameters:
      callable - the Callable object to be invoked on the event dispatch thread
      Returns:
      the return value of the callable returned in FutureTask.get()
      Throws:
      InterruptedException
      InvocationTargetException