Class LookAndFeelUtil

java.lang.Object
org.cytoscape.util.swing.LookAndFeelUtil

public final class LookAndFeelUtil extends Object
Class that provides useful methods to help create standard and consistent UI on the current Look and Feel and OS.

Cytoscape Backwards Compatibility (Final Class): This class is final and therefore can't be extended by users. This means that we may add methods for minor version updates. Methods will only be removed for major version updates.

Module: swing-util-api

To use this in your app, include the following dependency in your POM:

<dependency>
    <groupId>org.cytoscape</groupId>
    <artifactId>swing-util-api</artifactId>
</dependency>
  • Method Details

    • isAquaLAF

      public static boolean isAquaLAF()
      Returns:
      true if the current Look and Feel is "Aqua", usually available on Mac OS X only.
    • isNimbusLAF

      public static boolean isNimbusLAF()
      Returns:
      true if the current Look and Feel is "Nimbus".
    • isWinLAF

      public static boolean isWinLAF()
      Returns:
      true if the current Look and Feel is the Windows system one.
    • getInfoColor

      public static Color getInfoColor()
      Returns:
      The color that should be used on information icons or labels, for example.
    • getWarnColor

      public static Color getWarnColor()
      Returns:
      The color that should be used on warning icons or labels, for example.
    • getErrorColor

      public static Color getErrorColor()
      Returns:
      The color that should be used on error icons or labels, for example.
    • getSuccessColor

      public static Color getSuccessColor()
      Returns:
      The color that should be used on success related icons or labels.
    • getSmallFontSize

      public static float getSmallFontSize()
      Returns:
      The standard small font size for the current Look and feel.
    • createPanelBorder

      public static Border createPanelBorder()
      Use this method to create a simple panel Border which looks native on the current Look and Feel.
      Returns:
      The proper Border for the current Look and Feel.
    • createTitledBorder

      public static Border createTitledBorder(String title)
      Use this method to create a Titled Border which looks native on the current Look and Feel. The major problem is that the default border created by BorderFactory.createTitledBorder(String) does not look good on the "Aqua" Look and Feel (Mac OS X).
      Returns:
      The proper Border for the current Look and Feel.
    • createOkCancelPanel

      public static JPanel createOkCancelPanel(JButton okBtn, JButton cancelBtn)
      Use this method to create a standard Cytoscape panel (usually added to the bottom of a dialog) that contains an "OK" and/or a "Cancel" button. The buttons will be correctly positioned and aligned according to the current Look and Feel and OS.
      Parameters:
      okBtn - The button that executes the main action. It can be null.
      cancelBtn - The button that cancels the action (or simply closes a dialog). It can be null.
      Returns:
      A JPanel which contains the passed buttons.
    • createOkCancelPanel

      public static JPanel createOkCancelPanel(JButton okBtn, JButton cancelBtn, String helpStr)
      Use this method to create OK, Cancel and Help
      Parameters:
      helpStr - can be a full url, a lookup, or a help page name
    • createOkCancelPanel

      public static JPanel createOkCancelPanel(JButton okBtn, JButton cancelBtn, JComponent... otherComponents)
      Use this method to create a standard Cytoscape panel (usually added to the bottom of a dialog) that contains an "OK" and/or a "Cancel" button, as well as other extra components. The default OK/Cancel buttons and the extra components will be correctly positioned and aligned according to the current Look and Feel and OS.
      Parameters:
      okBtn - The button that executes the main action. It can be null.
      cancelBtn - The button that cancels the action (or simply closes a dialog). It can be null.
      otherComponents - Any other components to be included in the panel, such as check-boxes or other buttons.
      Returns:
      A JPanel which contains the passed components.
    • createOkCancelPanel

      public static JPanel createOkCancelPanel(JButton okBtn, JButton cancelBtn, String helpStr, JComponent... otherComponents)
      Use this method to include a help button in the bottom left corner.
      Parameters:
      helpStr - can be a full url, a lookup, or a help page name
    • createHelpButton

      public static JButton createHelpButton(String helpStr)
    • setDefaultOkCancelKeyStrokes

      public static void setDefaultOkCancelKeyStrokes(JRootPane rootPane, Action okAction, Action cancelAction)
      Maps the standard key strokes (usually ENTER and ESCAPE) to the passed OK and/or Cancel actions.
      Parameters:
      rootPane - A JDialog's root pane, for instance.
      okAction - The main Action of a JDialog, for instance. It can be null.
      cancelAction - The Action that cancels or closes a JDialog, for instance. It can be null.
    • equalizeSize

      public static void equalizeSize(JComponent... components)
      Resizes the given components making them equal in size.
    • makeSmall

      public static void makeSmall(JComponent... components)
      If one of the components is a JSlider, make sure this method is called after the slider has been added to its parent container and had its UI assigned, otherwise it will have no effect on the slider's labels.
      Also be careful when using this on a JList, because this could mess up the original ListCellRenderer.
    • isMac

      public static boolean isMac()
      Returns true if the current operating system is Mac OS X.
      Returns:
      true if the current OS is Mac OS X and false otherwise.
    • isWindows

      public static boolean isWindows()
      Returns true if the current operating system is any modern Windows distribution.
      Returns:
      true if the current OS is Windows and false otherwise.