Class JideSwingUtilities

  • All Implemented Interfaces:
    javax.swing.SwingConstants

    public class JideSwingUtilities
    extends java.lang.Object
    implements javax.swing.SwingConstants
    A utilities class for Swing.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.Object AA_TEXT_PROPERTY_KEY
      Key used in client properties to indicate whether or not the component should use aa text.
      static java.lang.String SET_OPAQUE_RECURSIVELY_EXCLUDED
      setOpaqueRecursively method will make all child components opaque true or false.
      protected static boolean tracingFocus  
      • Fields inherited from interface javax.swing.SwingConstants

        BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addSeparatorIfNecessary​(javax.swing.JPopupMenu popup)
      Adds a separator to the popup menu if there are menu items on it already.
      static java.awt.Dimension adjustPreferredScrollableViewportSize​(javax.swing.JList list, java.awt.Dimension defaultViewportSize)
      This method can be used to fix two JDK bugs.
      static int binarySearch​(int[] a, int key)
      Perform a binary search over a sorted array for the given key.
      static int binarySearch​(int[] a, int key, int start, int end)
      Perform a binary search over a sorted array for the given key.
      static <T> int binarySearch​(java.util.List<T> a, T key)
      Perform a binary search over a sorted list for the given key.
      static <T> int binarySearch​(T[] a, T key)
      Perform a binary search over a sorted array for the given key.
      static void centerWindow​(java.awt.Window childToCenter)
      Center the component to it's parent window.
      static boolean charsEqualIgnoreCase​(char a, char b)  
      static void clearGradientCache()
      Clears the gradient cache used for fast gradient painting
      static boolean componentIsPermanentFocusOwner​(java.awt.Component comp)  
      static boolean compositeRequestFocus​(java.awt.Component component)
      Copied from BasicLookAndFeel as the method is package local.
      static boolean containerContainsFocus​(java.awt.Container cont)
      containerContainsFocus, does the specified container contain the current focusOwner?
      static java.util.Vector convertDefaultComboBoxModelToVector​(javax.swing.DefaultComboBoxModel model)  
      static javax.swing.JPanel createBottomPanel​(java.awt.Component object)
      Create a Panel around a component so that component aligns to bottom.
      static javax.swing.JPanel createCenterPanel​(java.awt.Component object)
      Create a Panel around a component so that component is right in the middle.
      static javax.swing.JPanel createLabeledComponent​(javax.swing.JLabel title, java.awt.Component component, java.lang.Object constraint)
      Creates a container which a label for the component.
      static javax.swing.JPanel createLeftPanel​(java.awt.Component object)
      Create a Panel around a component so that component aligns to left.
      static javax.swing.JPanel createRightPanel​(java.awt.Component object)
      Create a Panel around a component so that component aligns to right.
      static javax.swing.JPanel createTableModelModifier​(javax.swing.table.DefaultTableModel tableModel)
      For internal usage only.
      static javax.swing.JPanel createTopPanel​(java.awt.Component object)
      Create a Panel around a component so that component aligns to top.
      static java.util.Map<java.awt.Component,​java.lang.Boolean> disableDoubleBuffered​(java.awt.Component c)
      Disables the double buffered flag of the component and its children.
      static void drawGrip​(java.awt.Graphics g, java.awt.Rectangle rectangle, int maxLength, int maxThickness)  
      static void drawGrip​(java.awt.Graphics g, java.awt.Rectangle rectangle, int maxLength, int maxThickness, boolean isSelected)  
      static void drawImageBorder​(java.awt.Graphics g, javax.swing.ImageIcon img, java.awt.Rectangle rect, java.awt.Insets ins, boolean drawCenter)
      Draws a border based on an image.
      static void drawShadow​(java.awt.Graphics g, java.awt.Component c, int x, int y, int w, int h)  
      static void drawString​(javax.swing.JComponent c, java.awt.Graphics g, java.lang.String text, int x, int y)  
      static void drawStringUnderlineCharAt​(javax.swing.JComponent c, java.awt.Graphics g, java.lang.String text, int underlinedIndex, int x, int y)  
      static boolean drawTextAntialiased​(boolean aaText)
      Returns whether or not text should be drawn anti-aliased.
      static java.util.Map<java.awt.Component,​java.lang.Boolean> enableDoubleBuffered​(java.awt.Component c)
      Enables the double buffered flag of the component and its children.
      static void ensureRowVisible​(javax.swing.JTable table, int row)
      To make sure the row is visible.
      static boolean equals​(java.lang.CharSequence s1, java.lang.CharSequence s2, boolean caseSensitive)  
      static boolean equals​(java.lang.Object o1, java.lang.Object o2)
      Checks if the two objects equal.
      static boolean equals​(java.lang.Object o1, java.lang.Object o2, boolean considerArrayOrList)
      Checks if the two objects equal.
      static boolean equals​(java.lang.Object o1, java.lang.Object o2, boolean considerArrayOrList, boolean caseSensitive)
      Checks if the two objects equal.
      static void fillGradient​(java.awt.Graphics2D g2d, java.awt.Shape s, java.awt.Color startColor, java.awt.Color endColor, boolean isVertical)
      Fills a gradient using the startColor and endColor specified.
      static void fillGradient​(java.awt.Graphics g, java.awt.Rectangle rect, int orientation)  
      static void fillNormalGradient​(java.awt.Graphics2D g2d, java.awt.Shape s, java.awt.Color startColor, java.awt.Color endColor, boolean isVertical)  
      static void fillSingleGradient​(java.awt.Graphics g, java.awt.Rectangle rect, int orientation)  
      static void fillSingleGradient​(java.awt.Graphics g, java.awt.Rectangle rect, int orientation, int level)  
      static int findDisplayedMnemonicIndex​(java.lang.String text, int mnemonic)  
      static java.awt.Component findFirstComponentByClass​(java.awt.Container c, java.lang.Class<?> clazz)
      Gets the first component inside the specified container that has the specified class.
      static java.awt.Component findFirstComponentByName​(java.awt.Container c, java.lang.String name)
      Gets the first component inside the specified container that has the specified name.
      static java.awt.Component findSomethingFocusable​(java.awt.Container container)
      Find some subcomponent of the specified container that will accept focus.
      static java.lang.Object getBoldFont​(java.awt.Toolkit toolkit, javax.swing.UIDefaults table)  
      static int[] getButtonState​(JideSplitButton b)  
      static int getButtonState​(javax.swing.AbstractButton b)  
      static java.lang.String getCancelString​(java.util.Locale locale)
      Gets the string representing Cancel button.
      static int getComponentIndex​(java.awt.Container container, java.awt.Component c)
      Get the index of the component in the container.
      static java.lang.Object getControlFont​(java.awt.Toolkit toolkit, javax.swing.UIDefaults table)  
      static java.lang.Object getControlFont​(java.awt.Toolkit toolkit, javax.swing.UIDefaults table, java.lang.String defaultUIDefault)  
      static float getDefaultFontSize()  
      static java.awt.Component getDescendantOfClass​(java.lang.Class c, java.awt.Container container)
      Gets the first occurrence of the component with specified type in the container.
      static java.awt.image.BufferedImage getFasterScaledInstance​(java.awt.image.BufferedImage img, int targetWidth, int targetHeight, java.lang.Object hint, boolean progressiveBilinear)
      Convenience method that returns a scaled instance of the provided BufferedImage.
      static java.awt.Component getFirstChildOf​(java.lang.Class<?> clazz, java.awt.Component c)
      Gets the first child of the component that is the specified type.
      static javax.swing.JComponent getFirstJComponent​(javax.swing.RootPaneContainer rootPaneContainer)
      Gets the first JComponent from the RootPaneContainer.
      static int getFocusAcceleratorKeyMask()  
      static java.awt.FontMetrics getFontMetrics​(javax.swing.JComponent c, java.awt.Graphics g)
      Copied from JDK's SwingUtilities2.java
      static java.awt.FontMetrics getFontMetrics​(javax.swing.JComponent c, java.awt.Graphics g, java.awt.Font font)
      Copied from JDK's SwingUtilities2.java
      static java.awt.Frame getFrame​(java.awt.Component component)
      Gets the top level Frame of the component.
      static java.awt.Paint getLinearGradientPaint​(float startX, float startY, float endX, float endY, float[] fractions, java.awt.Color[] colors)
      Gets the LinearGradientPaint.
      static int getLineHeight​(java.awt.Component c, int defaultHeight)
      Gets the line height for the font for the component
      static java.lang.Object getMenuFont​(java.awt.Toolkit toolkit, javax.swing.UIDefaults table)  
      static java.lang.String getNoString​(java.util.Locale locale)
      Gets the string representing No button.
      static java.lang.String getOKString​(java.util.Locale locale)
      Gets the string representing OK button.
      static int getOrientationOf​(java.awt.Component component)  
      static javax.swing.JRootPane getOutermostRootPane​(java.awt.Component c)
      If c is a JRootPane descendant return its outermost JRootPane ancestor.
      static java.awt.Dimension getPreferredButtonSize​(javax.swing.AbstractButton b, int textIconGap, boolean isHorizontal)  
      static java.awt.Paint getRadialGradientPaint​(float cx, float cy, float radius, float[] fractions, java.awt.Color[] colors)
      Gets the RadialGradientPaint.
      static java.awt.Paint getRadialGradientPaint​(java.awt.geom.Point2D point, float radius, float[] fractions, java.awt.Color[] colors)
      Gets the RadialGradientPaint.
      static java.awt.Component getRecursively​(java.awt.Component c, JideSwingUtilities.GetHandler handler)
      Gets to a child of a component recursively based on certain condition.
      static java.awt.Component getScrollPane​(java.awt.Component innerComponent)
      Gets the scroll pane around the component.
      static java.awt.Window getTopModalDialog​(java.awt.Window w)
      Gets the top modal dialog of current window.
      static javax.swing.event.ChangeListener getViewportSynchronizationChangeListener()  
      static java.awt.Window getWindowForComponent​(java.awt.Component parentComponent)
      Gets the top level Dialog or Frame of the component.
      static java.lang.String getYesString​(java.util.Locale locale)
      Gets the string representing Yes button.
      static void globalCenterWindow​(java.awt.Window childToCenter)
      Center the window to the whole screen.
      static void ignoreException​(java.lang.Exception e)
      Ignore the exception.
      static void insertKeyListener​(java.awt.Component component, java.awt.event.KeyListener l, int index)
      Inserts the key listener at the particular index in the listeners' chain.
      static void insertMouseListener​(java.awt.Component component, java.awt.event.MouseListener l, int index)
      Inserts the mouse listener at the particular index in the listeners' chain.
      static void insertMouseMotionListener​(java.awt.Component component, java.awt.event.MouseMotionListener l, int index)
      Inserts the mouse motion listener at the particular index in the listeners' chain.
      static void insertPropertyChangeListener​(java.awt.Component component, java.beans.PropertyChangeListener l, java.lang.String propertyName, int index)
      Inserts the property change listener at the particular index in the listeners' chain.
      static void insertPropertyChangeListener​(java.awt.KeyboardFocusManager manager, java.beans.PropertyChangeListener l, java.lang.String propertyName, int index)
      Inserts the property change listener at the particular index in the listeners' chain.
      static void insertTableModelListener​(javax.swing.table.TableModel model, javax.swing.event.TableModelListener l, int index)
      Inserts the table model listener at the particular index in the listeners' chain.
      static void installBorder​(javax.swing.JComponent c, javax.swing.border.Border defaultBorder)  
      static void installColors​(java.awt.Component c, java.awt.Color background, java.awt.Color foreground)  
      static void installColorsAndFont​(java.awt.Component c, java.awt.Color background, java.awt.Color foreground, java.awt.Font font)  
      static void installFont​(java.awt.Component c, java.awt.Font font)  
      static void invalidateRecursively​(java.awt.Component c)
      Invalidate and doLayout on the component and all its child components if any.
      static boolean isAncestorOfFocusOwner​(java.awt.Component component)  
      static boolean isFixedWidthFont​(java.lang.String fontName, java.awt.Component component)
      Checks if the font specified by the font name is fixed width font.
      static boolean isKeyListenerRegistered​(java.awt.Component component, java.awt.event.KeyListener l)
      Checks if the key listener is already registered on the component.
      static boolean isListenerRegistered​(java.awt.Component component, java.lang.Class t, java.util.EventListener l)
      Checks if the listener is always registered to the Component to avoid duplicated registration of the same listener
      static boolean isListenerRegistered​(javax.swing.event.EventListenerList list, java.lang.Class t, java.util.EventListener l)
      Checks if the listener is always registered to the EventListenerList to avoid duplicated registration of the same listener
      static boolean isMenuShortcutKeyDown​(java.awt.event.ActionEvent event)
      Checks if the ctrl key is pressed.
      static boolean isMenuShortcutKeyDown​(java.awt.event.InputEvent event)
      Checks if the ctrl key is pressed.
      static boolean isMouseListenerRegistered​(java.awt.Component component, java.awt.event.MouseListener l)
      Checks if the mouse listener is already registered on the component.
      static boolean isMouseMotionListenerRegistered​(java.awt.Component component, java.awt.event.MouseMotionListener l)
      Checks if the mouse motion listener is already registered on the component.
      static boolean isPropertyChangeListenerRegistered​(java.awt.Component component, java.beans.PropertyChangeListener l)
      Checks if the property change listener is already registered on the component.
      static boolean isPropertyChangeListenerRegistered​(java.awt.Component component, java.lang.String propertyName, java.beans.PropertyChangeListener l)
      Checks if the property change listener is already registered on the component.
      static java.lang.String layoutCompoundLabel​(java.awt.FontMetrics fm, java.lang.String text, javax.swing.Icon icon, boolean isHorizontal, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, java.awt.Rectangle viewR, java.awt.Rectangle iconR, java.awt.Rectangle textR, int textIconGap)
      Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string.
      static java.lang.String layoutCompoundLabel​(javax.swing.JComponent c, java.awt.FontMetrics fm, java.lang.String text, javax.swing.Icon icon, boolean isHorizontal, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, java.awt.Rectangle viewR, java.awt.Rectangle iconR, java.awt.Rectangle textR, int textIconGap)
      Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string.
      static void paintArrow​(java.awt.Graphics g, java.awt.Color color, int startX, int startY, int width, int orientation)
      Paints an arrow shape.
      static void paintArrow​(javax.swing.JComponent c, java.awt.Graphics g, java.awt.Color color, int startX, int startY, int width, int orientation)
      Paints an arrow shape.
      static void paintBackground​(java.awt.Graphics2D g2d, java.awt.Rectangle rect, java.awt.Color border, java.awt.Paint paint)  
      static void paintBackground​(java.awt.Graphics g, java.awt.Rectangle rect, java.awt.Color border, java.awt.Color bk)  
      static void paintCross​(java.awt.Graphics g, java.awt.Color color, int centerX, int centerY, int size, int width)
      Paints a cross shape.
      static boolean passesFocusabilityTest​(java.awt.Component comp)
      There are four standard tests which determine if Swing will be able to request focus for a component.
      static void printException​(java.lang.Exception e)
      Prints out the message of the exception.
      static void printUIDefaults()  
      static void putClientPropertyRecursively​(java.awt.Component c, java.lang.String clientProperty, java.lang.Object value)
      Calls putClientProperty method recursively on component and its child components as long as it is JComponent.
      static void registerTabKey​(java.awt.Container container)
      Register the tab key with the container.
      static void removeExtraSeparators​(javax.swing.JPopupMenu popup)
      Removes extra separators, if any.
      static void removeFromParentWithFocusTransfer​(java.awt.Component component)
      The semantics in AWT of hiding a component, removing a component, and reparenting a component are inconsistent with respect to focus.
      static void restoreAntialiasing​(java.awt.Component c, java.awt.Graphics g, java.lang.Object oldHints)
      Restores the old setting for text anti-alias.
      static void restoreDoubleBuffered​(java.awt.Component c, java.util.Map<java.awt.Component,​java.lang.Boolean> map)
      Restores the double buffered flag of the component and its children.
      static void restoreShapeAntialiasing​(java.awt.Graphics g, java.lang.Object oldHints)
      Restores the old setting for shape anti-alias.
      static void retargetMouseEvent​(int id, java.awt.event.MouseEvent e, java.awt.Component target)  
      static void runGCAndPrintFreeMemory()  
      static void setBounds​(java.awt.Container container, java.awt.Component component, int x, int y, int width, int height)
      Sets the bounds.
      static void setBounds​(java.awt.Container container, java.awt.Component component, java.awt.Rectangle bounds)
      Sets the bounds.
      static void setChildrenOrientationOf​(java.awt.Container c, int orientation)  
      static void setComponentTransparent​(javax.swing.JComponent component)
      Sets the text component transparent.
      static void setEnabledRecursively​(java.awt.Component c, boolean enabled)
      Calls setEnabled method recursively on component.
      static void setLocaleRecursively​(java.awt.Component c, java.util.Locale locale)
      Sets the locale recursively on the component and all its child components if any.
      static void setOpaqueRecursively​(java.awt.Component c, boolean opaque)
      Calls setOpaque method recursively on each component except for JButton, JComboBox and JTextComponent.
      static void setOrientationOf​(java.awt.Component component, int orientation)  
      static void setRecursively​(java.awt.Component c, JideSwingUtilities.Handler handler)
      Calls the handler recursively on a component.
      static void setRequestFocusEnabledRecursively​(java.awt.Component c, boolean enabled)
      Calls setRequestFocusEnabled method recursively on component.
      static void setTextComponentTransparent​(javax.swing.JComponent component)
      static java.lang.Object setupAntialiasing​(java.awt.Component c, java.awt.Graphics g)
      Setups the graphics to draw text using anti-alias.
      static java.lang.Object setupShapeAntialiasing​(java.awt.Graphics g)
      Setups the graphics to draw shape using anti-alias.
      static void setWindowOpacity​(java.awt.Window window, float opacity)
      Sets the Window opacity using AWTUtilities.setWindowOpacity on JDK6u10 and later.
      static void setWindowOpaque​(java.awt.Window window, boolean opaque)
      Sets the Window opaque using AWTUtilities.setWindowOpaque on JDK6u10 and later.
      static void setWindowShape​(java.awt.Window window, java.awt.Shape shape)
      Sets the Window shape using AWTUtilities.setWindowOpacity on JDK6u10 and later.
      static boolean shouldUseSystemFont()
      In JDK1.4, it uses a wrong font for Swing component in Windows L&F which is actually one big reason for people to think Swing application ugly.
      static void showPopupMenu​(javax.swing.JPopupMenu popup, java.awt.Component invoker, int x, int y)
      Shows the popup menu with the consideration of the invoker's orientation.
      static void synchronizeKeyboardActions​(javax.swing.JComponent sourceComponent, javax.swing.JComponent targetComponent, javax.swing.KeyStroke[] keyStrokes, int condition)
      Registers all actions registered on the source component and registered them on the target component at the specified condition.
      static void synchronizeView​(javax.swing.JViewport masterViewport, javax.swing.JViewport slaveViewport, int orientation)
      Synchronizes the two viewports.
      static void throwException​(java.lang.Exception e)
      Throws the exception.
      static void throwInvocationTargetException​(java.lang.reflect.InvocationTargetException e)
      Throws the InvocationTargetException.
      static void toggleRTLnLTR​(java.awt.Component topContainer)
      Toggles between RTL and LTR.
      static char toLowerCase​(char a)  
      static char toUpperCase​(char a)  
      static void traceFocus()
      For internal usage only.
      static void traceFocus​(boolean useBorders)
      For internal usage only.
      static void unsynchronizeView​(javax.swing.JViewport masterViewport, javax.swing.JViewport slaveViewport)
      Un-synchronizes the two viewport.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • AA_TEXT_PROPERTY_KEY

        public static final java.lang.Object AA_TEXT_PROPERTY_KEY
        Key used in client properties to indicate whether or not the component should use aa text.
      • SET_OPAQUE_RECURSIVELY_EXCLUDED

        public static final java.lang.String SET_OPAQUE_RECURSIVELY_EXCLUDED
        setOpaqueRecursively method will make all child components opaque true or false. But if you call jcomponent.putClientProperty(SET_OPAQUE_RECURSIVELY_EXCLUDED, Boolean.TRUE), we will not touch this particular component when setOpaqueRecursively.
        See Also:
        Constant Field Values
      • tracingFocus

        protected static boolean tracingFocus
    • Constructor Detail

      • JideSwingUtilities

        public JideSwingUtilities()
    • Method Detail

      • createLeftPanel

        public static javax.swing.JPanel createLeftPanel​(java.awt.Component object)
        Create a Panel around a component so that component aligns to left.
        Parameters:
        object - the component
        Returns:
        a Panel
      • createRightPanel

        public static javax.swing.JPanel createRightPanel​(java.awt.Component object)
        Create a Panel around a component so that component aligns to right.
        Parameters:
        object - the component
        Returns:
        a Panel
      • createTopPanel

        public static javax.swing.JPanel createTopPanel​(java.awt.Component object)
        Create a Panel around a component so that component aligns to top.
        Parameters:
        object - the component
        Returns:
        a Panel
      • createBottomPanel

        public static javax.swing.JPanel createBottomPanel​(java.awt.Component object)
        Create a Panel around a component so that component aligns to bottom.
        Parameters:
        object - the component
        Returns:
        a Panel
      • createCenterPanel

        public static javax.swing.JPanel createCenterPanel​(java.awt.Component object)
        Create a Panel around a component so that component is right in the middle.
        Parameters:
        object - the component
        Returns:
        a Panel
      • createLabeledComponent

        public static javax.swing.JPanel createLabeledComponent​(javax.swing.JLabel title,
                                                                java.awt.Component component,
                                                                java.lang.Object constraint)
        Creates a container which a label for the component.
        Parameters:
        title - the label
        component - the component
        constraint - the constraint as in BorderLayout. You can use all the constraints as in BorderLayout except CENTER.
        Returns:
        the container which has both the label and the component.
      • centerWindow

        public static void centerWindow​(java.awt.Window childToCenter)
        Center the component to it's parent window.
        Parameters:
        childToCenter - the parent window
      • globalCenterWindow

        public static void globalCenterWindow​(java.awt.Window childToCenter)
        Center the window to the whole screen.
        Parameters:
        childToCenter - the parent window
      • paintArrow

        public static void paintArrow​(java.awt.Graphics g,
                                      java.awt.Color color,
                                      int startX,
                                      int startY,
                                      int width,
                                      int orientation)
        Paints an arrow shape.
        Parameters:
        g - the graphics instance
        color - color
        startX - start X
        startY - start Y
        width - width
        orientation - horizontal or vertical
      • paintArrow

        public static void paintArrow​(javax.swing.JComponent c,
                                      java.awt.Graphics g,
                                      java.awt.Color color,
                                      int startX,
                                      int startY,
                                      int width,
                                      int orientation)
        Paints an arrow shape.
        Parameters:
        c - the component
        g - the graphics instance
        color - color
        startX - start X
        startY - start Y
        width - width
        orientation - horizontal or vertical
      • paintCross

        public static void paintCross​(java.awt.Graphics g,
                                      java.awt.Color color,
                                      int centerX,
                                      int centerY,
                                      int size,
                                      int width)
        Paints a cross shape.
        Parameters:
        g - the graphics instance
        color - color
        centerX - center X
        centerY - center Y
        size - size
        width - width
      • getFrame

        public static java.awt.Frame getFrame​(java.awt.Component component)
        Gets the top level Frame of the component.
        Parameters:
        component - the component
        Returns:
        the top level Frame. Null if we didn't find an ancestor which is instance of Frame.
      • toggleRTLnLTR

        public static void toggleRTLnLTR​(java.awt.Component topContainer)
        Toggles between RTL and LTR.
        Parameters:
        topContainer - the component
      • synchronizeView

        public static void synchronizeView​(javax.swing.JViewport masterViewport,
                                           javax.swing.JViewport slaveViewport,
                                           int orientation)
        Synchronizes the two viewports. The view position changes in the master view, the slave view's view position will change too. Generally speaking, if you want the two viewports to synchronize vertically, they should have the same height. If horizontally, the same width.

        It's OK if you call this method with the same master viewport and slave viewport duplicate times. It won't cause multiple events fired.

        Parameters:
        masterViewport - the master viewport
        slaveViewport - the slave viewport
        orientation - the orientation. It could be either SwingConstants.HORIZONTAL or SwingConstants.VERTICAL.
      • unsynchronizeView

        public static void unsynchronizeView​(javax.swing.JViewport masterViewport,
                                             javax.swing.JViewport slaveViewport)
        Un-synchronizes the two viewport.
        Parameters:
        masterViewport - the master viewport
        slaveViewport - the slave viewport
      • getButtonState

        public static int getButtonState​(javax.swing.AbstractButton b)
      • getButtonState

        public static int[] getButtonState​(JideSplitButton b)
      • equals

        public static boolean equals​(java.lang.Object o1,
                                     java.lang.Object o2)
        Checks if the two objects equal. If both are null, they are equal. If o1 and o2 both are Comparable, we will use compareTo method to see if it equals 0. At last, we will use o1.equals(o2) to compare. If none of the above conditions match, we return false.
        Parameters:
        o1 - the first object to compare
        o2 - the second object to compare
        Returns:
        true if the two objects are equal. Otherwise false.
      • equals

        public static boolean equals​(java.lang.Object o1,
                                     java.lang.Object o2,
                                     boolean considerArrayOrList)
        Checks if the two objects equal. If both are the same instance, they are equal. If both are null, they are equal. If o1 and o2 both are Comparable, we will use compareTo method to see if it equals 0. If considerArrayOrList is true and o1 and o2 are both array, we will compare each element in the array. At last, we will use o1.equals(o2) to compare. If none of the above conditions match, we return false.
        Parameters:
        o1 - the first object to compare
        o2 - the second object to compare
        considerArrayOrList - If true, and if o1 and o2 are both array, we will compare each element in the array instead of just compare the two array objects.
        Returns:
        true if the two objects are equal. Otherwise false.
      • equals

        public static boolean equals​(java.lang.Object o1,
                                     java.lang.Object o2,
                                     boolean considerArrayOrList,
                                     boolean caseSensitive)
        Checks if the two objects equal. If both are the same instance, they are equal. If both are null, they are equal. If o1 and o2 both are Comparable, we will use compareTo method to see if it equals 0. If considerArrayOrList is true and o1 and o2 are both array, we will compare each element in the array. At last, we will use o1.equals(o2) to compare. If none of the above conditions match, we return false.
        Parameters:
        o1 - the first object to compare
        o2 - the second object to compare
        considerArrayOrList - If true, and if o1 and o2 are both array, we will compare each element in the array instead of just compare the two array objects.
        caseSensitive - if the o1 and o2 are CharSequence, we will use this parameter to do a case sensitive or insensitive comparison
        Returns:
        true if the two objects are equal. Otherwise false.
      • equals

        public static boolean equals​(java.lang.CharSequence s1,
                                     java.lang.CharSequence s2,
                                     boolean caseSensitive)
      • charsEqualIgnoreCase

        public static boolean charsEqualIgnoreCase​(char a,
                                                   char b)
      • toUpperCase

        public static char toUpperCase​(char a)
      • toLowerCase

        public static char toLowerCase​(char a)
      • getFasterScaledInstance

        public static java.awt.image.BufferedImage getFasterScaledInstance​(java.awt.image.BufferedImage img,
                                                                           int targetWidth,
                                                                           int targetHeight,
                                                                           java.lang.Object hint,
                                                                           boolean progressiveBilinear)
        Convenience method that returns a scaled instance of the provided BufferedImage.
        Parameters:
        img - the original image to be scaled
        targetWidth - the desired width of the scaled instance, in pixels
        targetHeight - the desired height of the scaled instance, in pixels
        hint - one of the rendering hints that corresponds to RenderingHints.KEY_INTERPOLATION (e.g. RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR, RenderingHints.VALUE_INTERPOLATION_BILINEAR, RenderingHints.VALUE_INTERPOLATION_BICUBIC)
        progressiveBilinear - if true, this method will use a multi-step scaling technique that provides higher quality than the usual one-step technique (only useful in down-scaling cases, where targetWidth or targetHeight is smaller than the original dimensions)
        Returns:
        a scaled version of the original BufferedImage
      • getFocusAcceleratorKeyMask

        public static int getFocusAcceleratorKeyMask()
      • shouldUseSystemFont

        public static boolean shouldUseSystemFont()
        In JDK1.4, it uses a wrong font for Swing component in Windows L&F which is actually one big reason for people to think Swing application ugly. To address this issue, we changed the code to force to use Tahoma font for all the fonts in L&F instead of using the system font.

        However this is a downside to this. Tahoma cannot display Unicode characters such as Chinese, Japanese and Korean. So if the locale is CJK (SystemInfo.isCJKLocale(), we shouldn't use Tahoma. If you are on JDK 1.5 and above, you shouldn't force to use Tahoma either because JDK fixed it in 1.5 and above.

        There are also a few system properties you can set to control if system font should be used. "swing.useSystemFontSettings" is the one for all Swing applications. "Application.useSystemFontSettings" is the one for a particular Swing application.

        This method considers all the cases above. If JDK is 1.5 and above, this method will return true. If you are on Chinese, Japanese or Korean locale, it will return true. If "swing.useSystemFontSettings" property us true, it will return true. If "Application.useSystemFontSettings" property is true, it will return true. Otherwise, it will return false. All JIDE L&F considered the returned value and decide if Tahoma font should be used or not.

        Last but the least, we also add system property "jide.useSystemfont" which has the highest priority. If you set it to "true" or "false", this method will just check that value and return true or false respectively without looking at any other settings.

        Returns:
        true if the L&F should use system font.
      • printUIDefaults

        public static void printUIDefaults()
      • setRecursively

        public static void setRecursively​(java.awt.Component c,
                                          JideSwingUtilities.Handler handler)
        Calls the handler recursively on a component.
        Parameters:
        c - component
        handler - handler to be called
      • findFirstComponentByName

        public static java.awt.Component findFirstComponentByName​(java.awt.Container c,
                                                                  java.lang.String name)
        Gets the first component inside the specified container that has the specified name.
        Parameters:
        c - the container
        name - the name of the component
        Returns:
        the component. Null if not found.
      • findFirstComponentByClass

        public static java.awt.Component findFirstComponentByClass​(java.awt.Container c,
                                                                   java.lang.Class<?> clazz)
        Gets the first component inside the specified container that has the specified class.
        Parameters:
        c - the container
        clazz - the class of the component
        Returns:
        the component. Null if not found.
      • getRecursively

        public static java.awt.Component getRecursively​(java.awt.Component c,
                                                        JideSwingUtilities.GetHandler handler)
        Gets to a child of a component recursively based on certain condition.
        Parameters:
        c - component
        handler - handler to be called
        Returns:
        the component that matches the condition specified in GetHandler.
      • setEnabledRecursively

        public static void setEnabledRecursively​(java.awt.Component c,
                                                 boolean enabled)
        Calls setEnabled method recursively on component. Component c is usually a Container
        Parameters:
        c - component
        enabled - true if enable; false otherwise
      • putClientPropertyRecursively

        public static void putClientPropertyRecursively​(java.awt.Component c,
                                                        java.lang.String clientProperty,
                                                        java.lang.Object value)
        Calls putClientProperty method recursively on component and its child components as long as it is JComponent.
        Parameters:
        c - component
        clientProperty - the client property name
        value - the value for the client property
      • setRequestFocusEnabledRecursively

        public static void setRequestFocusEnabledRecursively​(java.awt.Component c,
                                                             boolean enabled)
        Calls setRequestFocusEnabled method recursively on component. Component c is usually a Container
        Parameters:
        c - component
        enabled - true if setRequestFocusEnabled to true; false otherwise
      • setOpaqueRecursively

        public static void setOpaqueRecursively​(java.awt.Component c,
                                                boolean opaque)
        Calls setOpaque method recursively on each component except for JButton, JComboBox and JTextComponent. Component c is usually a Container. If you would like certain child component not affected by this call, you can call jcomponent.putClientProperty(SET_OPAQUE_RECURSIVELY_EXCLUDED, Boolean.TRUE) before calling this method.
        Parameters:
        c - component
        opaque - true if setOpaque to true; false otherwise
      • getPreferredButtonSize

        public static java.awt.Dimension getPreferredButtonSize​(javax.swing.AbstractButton b,
                                                                int textIconGap,
                                                                boolean isHorizontal)
      • layoutCompoundLabel

        public static java.lang.String layoutCompoundLabel​(javax.swing.JComponent c,
                                                           java.awt.FontMetrics fm,
                                                           java.lang.String text,
                                                           javax.swing.Icon icon,
                                                           boolean isHorizontal,
                                                           int verticalAlignment,
                                                           int horizontalAlignment,
                                                           int verticalTextPosition,
                                                           int horizontalTextPosition,
                                                           java.awt.Rectangle viewR,
                                                           java.awt.Rectangle iconR,
                                                           java.awt.Rectangle textR,
                                                           int textIconGap)
        Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string. Locations are computed relative to the viewR rectangle. The JComponents orientation (LEADING/TRAILING) will also be taken into account and translated into LEFT/RIGHT values accordingly.
        Parameters:
        c - the component
        fm - the font metrics
        text - the text
        icon - the icon
        isHorizontal - the flag indicating horizontal or vertical
        verticalAlignment - vertical alignment model
        horizontalAlignment - horizontal alignment model
        verticalTextPosition - vertical text position
        horizontalTextPosition - horizontal text position
        viewR - view rectangle
        iconR - icon rectangle
        textR - text rectangle
        textIconGap - the gap between the text and the gap
        Returns:
        the string after layout.
      • layoutCompoundLabel

        public static java.lang.String layoutCompoundLabel​(java.awt.FontMetrics fm,
                                                           java.lang.String text,
                                                           javax.swing.Icon icon,
                                                           boolean isHorizontal,
                                                           int verticalAlignment,
                                                           int horizontalAlignment,
                                                           int verticalTextPosition,
                                                           int horizontalTextPosition,
                                                           java.awt.Rectangle viewR,
                                                           java.awt.Rectangle iconR,
                                                           java.awt.Rectangle textR,
                                                           int textIconGap)
        Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string. Locations are computed relative to the viewR rectangle. This layoutCompoundLabel() does not know how to handle LEADING/TRAILING values in horizontalTextPosition (they will default to RIGHT) and in horizontalAlignment (they will default to CENTER). Use the other version of layoutCompoundLabel() instead.
        Parameters:
        fm - the font metrics
        text - the text to layout
        icon - the icon to layout
        isHorizontal - if the layout is horizontal
        verticalAlignment - the vertical alignment
        horizontalAlignment - the horizontal alignment
        verticalTextPosition - the vertical text position
        horizontalTextPosition - the horizontal text position
        viewR - the view rectangle
        iconR - the icon rectangle
        textR - the text rectangle
        textIconGap - the gap between the text and the icon
        Returns:
        the string after layout.
      • getOrientationOf

        public static int getOrientationOf​(java.awt.Component component)
      • setOrientationOf

        public static void setOrientationOf​(java.awt.Component component,
                                            int orientation)
      • setChildrenOrientationOf

        public static void setChildrenOrientationOf​(java.awt.Container c,
                                                    int orientation)
      • disableDoubleBuffered

        public static java.util.Map<java.awt.Component,​java.lang.Boolean> disableDoubleBuffered​(java.awt.Component c)
        Disables the double buffered flag of the component and its children. The return map contains the components that were double buffered. After this call, you can then restore the double buffered flag using restoreDoubleBuffered(java.awt.Component, java.util.Map) using the map that is returned from this method.
        Parameters:
        c - the parent container.
        Returns:
        the map that contains all components that were double buffered.
      • enableDoubleBuffered

        public static java.util.Map<java.awt.Component,​java.lang.Boolean> enableDoubleBuffered​(java.awt.Component c)
        Enables the double buffered flag of the component and its children. The return map contains the components that weren't double buffered. After this call, you can then restore the double buffered flag using restoreDoubleBuffered(java.awt.Component, java.util.Map) using the map that is returned from this method.
        Parameters:
        c - the parent container.
        Returns:
        the map that contains all components that weren't double buffered.
      • restoreDoubleBuffered

        public static void restoreDoubleBuffered​(java.awt.Component c,
                                                 java.util.Map<java.awt.Component,​java.lang.Boolean> map)
        Restores the double buffered flag of the component and its children. Only components that are in the map will be changed.
        Parameters:
        c - the parent container.
        map - a map maps from component to a boolean. If the boolean is true, it means the component was double buffered bore. Otherwise, not double buffered.
      • paintBackground

        public static void paintBackground​(java.awt.Graphics g,
                                           java.awt.Rectangle rect,
                                           java.awt.Color border,
                                           java.awt.Color bk)
      • paintBackground

        public static void paintBackground​(java.awt.Graphics2D g2d,
                                           java.awt.Rectangle rect,
                                           java.awt.Color border,
                                           java.awt.Paint paint)
      • drawTextAntialiased

        public static boolean drawTextAntialiased​(boolean aaText)
        Returns whether or not text should be drawn anti-aliased.
        Parameters:
        aaText - Whether or not aa text has been turned on for the component.
        Returns:
        Whether or not text should be drawn anti-aliased.
      • drawStringUnderlineCharAt

        public static void drawStringUnderlineCharAt​(javax.swing.JComponent c,
                                                     java.awt.Graphics g,
                                                     java.lang.String text,
                                                     int underlinedIndex,
                                                     int x,
                                                     int y)
      • drawString

        public static void drawString​(javax.swing.JComponent c,
                                      java.awt.Graphics g,
                                      java.lang.String text,
                                      int x,
                                      int y)
      • setupAntialiasing

        public static java.lang.Object setupAntialiasing​(java.awt.Component c,
                                                         java.awt.Graphics g)
        Setups the graphics to draw text using anti-alias.

        Under JDK1.4 and JDK5, this method will use a system property "swing.aatext" to determine if anti-alias is used. Under JDK6, we will read the system setting. For example, on Windows XP, there is a check box to turn on clear type anti-alias. We will use the same settings.

        Parameters:
        c - the component
        g - the Graphics instance
        Returns:
        the old hints. You will need this value as the third parameter in restoreAntialiasing(java.awt.Component, java.awt.Graphics, Object).
      • restoreAntialiasing

        public static void restoreAntialiasing​(java.awt.Component c,
                                               java.awt.Graphics g,
                                               java.lang.Object oldHints)
        Restores the old setting for text anti-alias.
        Parameters:
        c -
        g -
        oldHints - the value returned from setupAntialiasing(java.awt.Component, java.awt.Graphics).
      • setupShapeAntialiasing

        public static java.lang.Object setupShapeAntialiasing​(java.awt.Graphics g)
        Setups the graphics to draw shape using anti-alias.
        Parameters:
        g -
        Returns:
        the old hints. You will need this value as the third parameter in restoreShapeAntialiasing(java.awt.Graphics, Object).
      • restoreShapeAntialiasing

        public static void restoreShapeAntialiasing​(java.awt.Graphics g,
                                                    java.lang.Object oldHints)
        Restores the old setting for shape anti-alias.
        Parameters:
        g -
        oldHints - the value returned from setupShapeAntialiasing(java.awt.Graphics).
      • drawGrip

        public static void drawGrip​(java.awt.Graphics g,
                                    java.awt.Rectangle rectangle,
                                    int maxLength,
                                    int maxThickness)
      • drawGrip

        public static void drawGrip​(java.awt.Graphics g,
                                    java.awt.Rectangle rectangle,
                                    int maxLength,
                                    int maxThickness,
                                    boolean isSelected)
      • registerTabKey

        public static void registerTabKey​(java.awt.Container container)
        Register the tab key with the container.
        Parameters:
        container -
      • fillGradient

        public static void fillGradient​(java.awt.Graphics g,
                                        java.awt.Rectangle rect,
                                        int orientation)
      • fillSingleGradient

        public static void fillSingleGradient​(java.awt.Graphics g,
                                              java.awt.Rectangle rect,
                                              int orientation)
      • fillSingleGradient

        public static void fillSingleGradient​(java.awt.Graphics g,
                                              java.awt.Rectangle rect,
                                              int orientation,
                                              int level)
      • getRadialGradientPaint

        public static java.awt.Paint getRadialGradientPaint​(java.awt.geom.Point2D point,
                                                            float radius,
                                                            float[] fractions,
                                                            java.awt.Color[] colors)
        Gets the RadialGradientPaint. RadialGradientPaint is added after JDK6. If you are running JDK5 or before, you can include batik-awt-util.jar which also has a RadialGradientPaint class. This method will use reflection to determine if the RadialGradientPaint class is in the class path and use the one it can find.
      • getRadialGradientPaint

        public static java.awt.Paint getRadialGradientPaint​(float cx,
                                                            float cy,
                                                            float radius,
                                                            float[] fractions,
                                                            java.awt.Color[] colors)
        Gets the RadialGradientPaint. RadialGradientPaint is added after JDK6. If you are running JDK5 or before, you can include batik-awt-util.jar which also has a RadialGradientPaint class. This method will use reflection to determine if the RadialGradientPaint class is in the class path and use the one it can find.
      • getLinearGradientPaint

        public static java.awt.Paint getLinearGradientPaint​(float startX,
                                                            float startY,
                                                            float endX,
                                                            float endY,
                                                            float[] fractions,
                                                            java.awt.Color[] colors)
        Gets the LinearGradientPaint. LinearGradientPaint is added after JDK6. If you are running JDK5 or before, you can include batik-awt-util.jar which also has a LinearGradientPaint class. This method will use reflection to determine if the LinearGradientPaint class is in the class path and use the one it can find.
      • containerContainsFocus

        public static boolean containerContainsFocus​(java.awt.Container cont)
        containerContainsFocus, does the specified container contain the current focusOwner?
        Parameters:
        cont - the specified container
        Returns:
        Is the current focusOwner a descendant of the specified container, or the container itself?
      • componentIsPermanentFocusOwner

        public static boolean componentIsPermanentFocusOwner​(java.awt.Component comp)
      • installColorsAndFont

        public static void installColorsAndFont​(java.awt.Component c,
                                                java.awt.Color background,
                                                java.awt.Color foreground,
                                                java.awt.Font font)
      • installFont

        public static void installFont​(java.awt.Component c,
                                       java.awt.Font font)
      • installColors

        public static void installColors​(java.awt.Component c,
                                         java.awt.Color background,
                                         java.awt.Color foreground)
      • installBorder

        public static void installBorder​(javax.swing.JComponent c,
                                         javax.swing.border.Border defaultBorder)
      • fillNormalGradient

        public static void fillNormalGradient​(java.awt.Graphics2D g2d,
                                              java.awt.Shape s,
                                              java.awt.Color startColor,
                                              java.awt.Color endColor,
                                              boolean isVertical)
      • fillGradient

        public static void fillGradient​(java.awt.Graphics2D g2d,
                                        java.awt.Shape s,
                                        java.awt.Color startColor,
                                        java.awt.Color endColor,
                                        boolean isVertical)
        Fills a gradient using the startColor and endColor specified. This is a fast version of fill gradient which will not only leverage hardware acceleration, but also cache GradientPaint and reuse it.

        We also leave an option to use the normal GradientPaint to paint the gradient. To do so, just set a system property "normalGradientPaint" to "false".

        Parameters:
        g2d -
        s -
        startColor -
        endColor -
        isVertical -
      • clearGradientCache

        public static void clearGradientCache()
        Clears the gradient cache used for fast gradient painting
      • getTopModalDialog

        public static java.awt.Window getTopModalDialog​(java.awt.Window w)
        Gets the top modal dialog of current window.
        Parameters:
        w -
        Returns:
        the top modal dialog of current window.
      • traceFocus

        public static void traceFocus()
        For internal usage only.
      • traceFocus

        public static void traceFocus​(boolean useBorders)
        For internal usage only.
      • runGCAndPrintFreeMemory

        public static void runGCAndPrintFreeMemory()
      • createTableModelModifier

        public static javax.swing.JPanel createTableModelModifier​(javax.swing.table.DefaultTableModel tableModel)
        For internal usage only.
      • findSomethingFocusable

        public static java.awt.Component findSomethingFocusable​(java.awt.Container container)
        Find some subcomponent of the specified container that will accept focus.

        Note that this doesn't do something smart like trying to walk the hierarchy horizontally at each level so that the focused subcomponent is as high as possible. Rather, it drills vertically. It's just a safety valve so that focus can be requested somewhere rather than being lost.

        Parameters:
        container -
        Returns:
        a focusable subcomponent
      • passesFocusabilityTest

        public static boolean passesFocusabilityTest​(java.awt.Component comp)
        There are four standard tests which determine if Swing will be able to request focus for a component. Test them.
        Parameters:
        comp -
        Returns:
        does the specified component pass the four focusability tests
      • ignoreException

        public static void ignoreException​(java.lang.Exception e)
        Ignore the exception. This method does nothing. However it's a good practice to use this method so that we can easily find out the place that ignoring exception. In development phase, we can log a message in this method so that we can verify if it makes sense to ignore.
        Parameters:
        e -
      • printException

        public static void printException​(java.lang.Exception e)
        Prints out the message of the exception.
        Parameters:
        e -
      • throwException

        public static void throwException​(java.lang.Exception e)
        Throws the exception. If the exception is RuntimeException, just throw it. Otherwise, wrap it in RuntimeException and throw it.
        Parameters:
        e -
      • throwInvocationTargetException

        public static void throwInvocationTargetException​(java.lang.reflect.InvocationTargetException e)
        Throws the InvocationTargetException. Usually InvocationTargetException has a nested exception as target exception. If the target exception is a RuntimeException or Error, we will throw it. Otherwise, we will wrap it inside RuntimeException and throw it.
        Parameters:
        e -
      • findDisplayedMnemonicIndex

        public static int findDisplayedMnemonicIndex​(java.lang.String text,
                                                     int mnemonic)
      • getDescendantOfClass

        public static java.awt.Component getDescendantOfClass​(java.lang.Class c,
                                                              java.awt.Container container)
        Gets the first occurrence of the component with specified type in the container. It used deep-first searching to find it.
        Parameters:
        c -
        container -
        Returns:
        the first occurrence of the component with specified type in the container. Null if nothing is found.
      • getDefaultFontSize

        public static float getDefaultFontSize()
      • getMenuFont

        public static java.lang.Object getMenuFont​(java.awt.Toolkit toolkit,
                                                   javax.swing.UIDefaults table)
      • getControlFont

        public static java.lang.Object getControlFont​(java.awt.Toolkit toolkit,
                                                      javax.swing.UIDefaults table,
                                                      java.lang.String defaultUIDefault)
      • getControlFont

        public static java.lang.Object getControlFont​(java.awt.Toolkit toolkit,
                                                      javax.swing.UIDefaults table)
      • getBoldFont

        public static java.lang.Object getBoldFont​(java.awt.Toolkit toolkit,
                                                   javax.swing.UIDefaults table)
      • drawShadow

        public static void drawShadow​(java.awt.Graphics g,
                                      java.awt.Component c,
                                      int x,
                                      int y,
                                      int w,
                                      int h)
      • drawImageBorder

        public static void drawImageBorder​(java.awt.Graphics g,
                                           javax.swing.ImageIcon img,
                                           java.awt.Rectangle rect,
                                           java.awt.Insets ins,
                                           boolean drawCenter)
        Draws a border based on an image. The image can be divided into nine different areas. Each area size is determined by the insets.
      • compositeRequestFocus

        public static boolean compositeRequestFocus​(java.awt.Component component)
        Copied from BasicLookAndFeel as the method is package local.
        Parameters:
        component -
        Returns:
        if request focus is success or not.
      • isAncestorOfFocusOwner

        public static boolean isAncestorOfFocusOwner​(java.awt.Component component)
      • getWindowForComponent

        public static java.awt.Window getWindowForComponent​(java.awt.Component parentComponent)
                                                     throws java.awt.HeadlessException
        Gets the top level Dialog or Frame of the component.
        Parameters:
        parentComponent -
        Returns:
        the top level Frame or Dialog. Null if we didn't find an ancestor which is instance of Frame.
        Throws:
        java.awt.HeadlessException
      • isKeyListenerRegistered

        public static boolean isKeyListenerRegistered​(java.awt.Component component,
                                                      java.awt.event.KeyListener l)
        Checks if the key listener is already registered on the component.
        Parameters:
        component - the component
        l - the listener
        Returns:
        true if already registered. Otherwise false.
      • insertKeyListener

        public static void insertKeyListener​(java.awt.Component component,
                                             java.awt.event.KeyListener l,
                                             int index)
        Inserts the key listener at the particular index in the listeners' chain.
        Parameters:
        component -
        l -
        index -
      • insertTableModelListener

        public static void insertTableModelListener​(javax.swing.table.TableModel model,
                                                    javax.swing.event.TableModelListener l,
                                                    int index)
        Inserts the table model listener at the particular index in the listeners' chain. The listeners are fired in reverse order. So the listener at index 0 will be fired at last.
        Parameters:
        model - the AbstractTableModel
        l - the TableModelListener to be inserted
        index - the index.
      • insertPropertyChangeListener

        public static void insertPropertyChangeListener​(java.awt.Component component,
                                                        java.beans.PropertyChangeListener l,
                                                        java.lang.String propertyName,
                                                        int index)
        Inserts the property change listener at the particular index in the listeners' chain.
        Parameters:
        component - the component where the listener will be inserted.
        l - the listener to be inserted
        propertyName - the name of the property. Could be null.
        index - the index to be inserted
      • insertPropertyChangeListener

        public static void insertPropertyChangeListener​(java.awt.KeyboardFocusManager manager,
                                                        java.beans.PropertyChangeListener l,
                                                        java.lang.String propertyName,
                                                        int index)
        Inserts the property change listener at the particular index in the listeners' chain.
        Parameters:
        manager - the KeyboardFocusManager where the listener will be inserted.
        l - the listener to be inserted
        propertyName - the name of the property. Could be null.
        index - the index to be inserted
      • isPropertyChangeListenerRegistered

        public static boolean isPropertyChangeListenerRegistered​(java.awt.Component component,
                                                                 java.beans.PropertyChangeListener l)
        Checks if the property change listener is already registered on the component.
        Parameters:
        component - the component
        l - the listener
        Returns:
        true if already registered. Otherwise false.
      • isPropertyChangeListenerRegistered

        public static boolean isPropertyChangeListenerRegistered​(java.awt.Component component,
                                                                 java.lang.String propertyName,
                                                                 java.beans.PropertyChangeListener l)
        Checks if the property change listener is already registered on the component.
        Parameters:
        component - the component
        propertyName - the property name
        l - the listener
        Returns:
        true if already registered. Otherwise false.
      • isMouseListenerRegistered

        public static boolean isMouseListenerRegistered​(java.awt.Component component,
                                                        java.awt.event.MouseListener l)
        Checks if the mouse listener is already registered on the component.
        Parameters:
        component - the component
        l - the listener
        Returns:
        true if already registered. Otherwise false.
      • insertMouseListener

        public static void insertMouseListener​(java.awt.Component component,
                                               java.awt.event.MouseListener l,
                                               int index)
        Inserts the mouse listener at the particular index in the listeners' chain.
        Parameters:
        component -
        l -
        index -
      • isMouseMotionListenerRegistered

        public static boolean isMouseMotionListenerRegistered​(java.awt.Component component,
                                                              java.awt.event.MouseMotionListener l)
        Checks if the mouse motion listener is already registered on the component.
        Parameters:
        component - the component
        l - the listener
        Returns:
        true if already registered. Otherwise false.
      • insertMouseMotionListener

        public static void insertMouseMotionListener​(java.awt.Component component,
                                                     java.awt.event.MouseMotionListener l,
                                                     int index)
        Inserts the mouse motion listener at the particular index in the listeners' chain.
        Parameters:
        component -
        l -
        index -
      • getScrollPane

        public static java.awt.Component getScrollPane​(java.awt.Component innerComponent)
        Gets the scroll pane around the component.
        Parameters:
        innerComponent -
        Returns:
        the scroll pane. Null if the component is not in any JScrollPane.
      • isListenerRegistered

        public static boolean isListenerRegistered​(javax.swing.event.EventListenerList list,
                                                   java.lang.Class t,
                                                   java.util.EventListener l)
        Checks if the listener is always registered to the EventListenerList to avoid duplicated registration of the same listener
        Parameters:
        list - the EventListenerList to register the listener.
        t - the type of the EventListener.
        l - the listener.
        Returns:
        true if already registered. Otherwise false.
      • isListenerRegistered

        public static boolean isListenerRegistered​(java.awt.Component component,
                                                   java.lang.Class t,
                                                   java.util.EventListener l)
        Checks if the listener is always registered to the Component to avoid duplicated registration of the same listener
        Parameters:
        component - the component that you want to register the listener.
        t - the type of the EventListener.
        l - the listener.
        Returns:
        true if already registered. Otherwise false.
      • getFirstChildOf

        public static java.awt.Component getFirstChildOf​(java.lang.Class<?> clazz,
                                                         java.awt.Component c)
        Gets the first child of the component that is the specified type.
        Parameters:
        clazz - the type of the component to look for
        c - the component
        Returns:
        the first child of the component that is the specified type.
      • getComponentIndex

        public static int getComponentIndex​(java.awt.Container container,
                                            java.awt.Component c)
        Get the index of the component in the container. It will return -1 if c's parent is not container.
        Parameters:
        container - the container
        c - the component
        Returns:
        the index
      • convertDefaultComboBoxModelToVector

        public static java.util.Vector convertDefaultComboBoxModelToVector​(javax.swing.DefaultComboBoxModel model)
      • ensureRowVisible

        public static void ensureRowVisible​(javax.swing.JTable table,
                                            int row)
        To make sure the row is visible. If the table's horizontal scroll bar is visible, the method will not change the horizontal scroll bar's position.
        Parameters:
        table -
        row -
      • retargetMouseEvent

        public static void retargetMouseEvent​(int id,
                                              java.awt.event.MouseEvent e,
                                              java.awt.Component target)
      • getOutermostRootPane

        public static javax.swing.JRootPane getOutermostRootPane​(java.awt.Component c)
        If c is a JRootPane descendant return its outermost JRootPane ancestor. If c is a RootPaneContainer then return its JRootPane.
        Parameters:
        c - the component.
        Returns:
        the outermost JRootPane for Component c or null.
      • isFixedWidthFont

        public static boolean isFixedWidthFont​(java.lang.String fontName,
                                               java.awt.Component component)
        Checks if the font specified by the font name is fixed width font. Fixed width font means all chars have the exact same width.
        Parameters:
        fontName - the font name
        component - the component where the font will be displayed.
        Returns:
        true if the font is fixed width. Otherwise false.
      • setLocaleRecursively

        public static void setLocaleRecursively​(java.awt.Component c,
                                                java.util.Locale locale)
        Sets the locale recursively on the component and all its child components if any.
        Parameters:
        c - the component
        locale - the new locales.
      • setBounds

        public static void setBounds​(java.awt.Container container,
                                     java.awt.Component component,
                                     java.awt.Rectangle bounds)
        Sets the bounds. If the container orientation is from right to left, this method will adjust the x to the opposite.
        Parameters:
        container - the container. It is usually the parent of the component.
        component - the component to set bounds
        bounds - the bounds.
      • setBounds

        public static void setBounds​(java.awt.Container container,
                                     java.awt.Component component,
                                     int x,
                                     int y,
                                     int width,
                                     int height)
        Sets the bounds. If the container orientation is from right to left, this method will adjust the x to the opposite.
        Parameters:
        container - the container. It is usually the parent of the component.
        component - the component to set bounds
        x - the x of the bounds
        y - the y of the bounds
        width - the the height of the bounds. of the bounds.
        height - the height of the bounds.
      • invalidateRecursively

        public static void invalidateRecursively​(java.awt.Component c)
        Invalidate and doLayout on the component and all its child components if any.
        Parameters:
        c - the component
      • synchronizeKeyboardActions

        public static void synchronizeKeyboardActions​(javax.swing.JComponent sourceComponent,
                                                      javax.swing.JComponent targetComponent,
                                                      javax.swing.KeyStroke[] keyStrokes,
                                                      int condition)
        Registers all actions registered on the source component and registered them on the target component at the specified condition.
        Parameters:
        sourceComponent - the source component.
        targetComponent - the target component.
        keyStrokes - the keystrokes
        condition - the condition which will be used in JComponent.registerKeyboardAction(java.awt.event.ActionListener, javax.swing.KeyStroke, int) as the last parameter.
      • getFirstJComponent

        public static javax.swing.JComponent getFirstJComponent​(javax.swing.RootPaneContainer rootPaneContainer)
        Gets the first JComponent from the RootPaneContainer.
        Parameters:
        rootPaneContainer - a rootPaneContainer
        Returns:
        the first JComponent from the rootPaneContainer's content pane.
      • adjustPreferredScrollableViewportSize

        public static java.awt.Dimension adjustPreferredScrollableViewportSize​(javax.swing.JList list,
                                                                               java.awt.Dimension defaultViewportSize)
        This method can be used to fix two JDK bugs. One is to fix the row height is wrong when the first element in the model is null or empty string. The second bug is only on JDK1.4.2 where the vertical scroll bar is shown even all rows are visible. To use it, you just need to override JList#getPreferredScrollableViewportSize and call this method.
        
         public Dimension getPreferredScrollableViewportSize() {
            return JideSwingUtilities.adjustPreferredScrollableViewportSize(this, super.getPreferredScrollableViewportSize());
         }
         

        Parameters:
        list - the JList
        defaultViewportSize - the default viewport size from JList#getPreferredScrollableViewportSize().
        Returns:
        the adjusted size.
      • removeFromParentWithFocusTransfer

        public static void removeFromParentWithFocusTransfer​(java.awt.Component component)
        The semantics in AWT of hiding a component, removing a component, and reparenting a component are inconsistent with respect to focus. By calling this function before any of the operations above focus is guaranteed a consistent degregation.
        Parameters:
        component -
      • getLineHeight

        public static int getLineHeight​(java.awt.Component c,
                                        int defaultHeight)
        Gets the line height for the font for the component
        Parameters:
        c - the component
        defaultHeight - the default height if the font on the specified component is null
        Returns:
        the line height for the font for the component (or the passed in the default value if the font on the specified component is null)
      • addSeparatorIfNecessary

        public static void addSeparatorIfNecessary​(javax.swing.JPopupMenu popup)
        Adds a separator to the popup menu if there are menu items on it already.
        Parameters:
        popup - the popup menu.
      • removeExtraSeparators

        public static void removeExtraSeparators​(javax.swing.JPopupMenu popup)
        Removes extra separators, if any. This can be used when you remove some menu items and leave extra separators on the UI.
        Parameters:
        popup - the popup menu.
      • setTextComponentTransparent

        @Deprecated
        public static void setTextComponentTransparent​(javax.swing.JComponent component)
        Sets the text component transparent. It will call setOpaque(false) and also set client property for certain L&Fs in case the L&F doesn't respect the opaque flag.
        Parameters:
        component - the text component to be set to transparent.
      • setComponentTransparent

        public static void setComponentTransparent​(javax.swing.JComponent component)
        Sets the text component transparent. It will call setOpaque(false) and also set client property for certain L&Fs in case the L&F doesn't respect the opaque flag.
        Parameters:
        component - the text component to be set to transparent.
      • binarySearch

        public static <T> int binarySearch​(java.util.List<T> a,
                                           T key)
        Perform a binary search over a sorted list for the given key.
        Parameters:
        a - the array to search
        key - the key to search for
        Returns:
        the index of the given key if it exists in the list, otherwise -1 times the index value at the insertion point that would be used if the key were added to the list.
      • binarySearch

        public static <T> int binarySearch​(T[] a,
                                           T key)
        Perform a binary search over a sorted array for the given key.
        Parameters:
        a - the array to search
        key - the key to search for
        Returns:
        the index of the given key if it exists in the array, otherwise -1 times the index value at the insertion point that would be used if the key were added to the array.
      • binarySearch

        public static int binarySearch​(int[] a,
                                       int key)
        Perform a binary search over a sorted array for the given key.
        Parameters:
        a - the array to search
        key - the key to search for
        Returns:
        the index of the given key if it exists in the array, otherwise -1 times the index value at the insertion point that would be used if the key were added to the array.
      • binarySearch

        public static int binarySearch​(int[] a,
                                       int key,
                                       int start,
                                       int end)
        Perform a binary search over a sorted array for the given key.
        Parameters:
        a - the array to search
        key - the key to search for
        start - the start index to search inclusive
        end - the end index to search exclusive
        Returns:
        the index of the given key if it exists in the array, otherwise -1 times the index value at the insertion point that would be used if the key were added to the array.
      • isMenuShortcutKeyDown

        public static boolean isMenuShortcutKeyDown​(java.awt.event.InputEvent event)
        Checks if the ctrl key is pressed. On Mac oS X, it will be command key.
        Parameters:
        event - the InputEvent.
        Returns:
        true or false.
      • isMenuShortcutKeyDown

        public static boolean isMenuShortcutKeyDown​(java.awt.event.ActionEvent event)
        Checks if the ctrl key is pressed. On Mac oS X, it will be command key.
        Parameters:
        event - the InputEvent.
        Returns:
        true or false.
      • getViewportSynchronizationChangeListener

        public static javax.swing.event.ChangeListener getViewportSynchronizationChangeListener()
      • setWindowOpaque

        public static void setWindowOpaque​(java.awt.Window window,
                                           boolean opaque)
        Sets the Window opaque using AWTUtilities.setWindowOpaque on JDK6u10 and later.
        Parameters:
        window - the Window
        opaque - true or false
      • setWindowOpacity

        public static void setWindowOpacity​(java.awt.Window window,
                                            float opacity)
        Sets the Window opacity using AWTUtilities.setWindowOpacity on JDK6u10 and later.
        Parameters:
        window - the Window
        opacity - the opacity
      • setWindowShape

        public static void setWindowShape​(java.awt.Window window,
                                          java.awt.Shape shape)
        Sets the Window shape using AWTUtilities.setWindowOpacity on JDK6u10 and later.
        Parameters:
        window - the Window
        shape - the shape
      • getOKString

        public static java.lang.String getOKString​(java.util.Locale locale)
        Gets the string representing OK button.
        Parameters:
        locale - the locale
        Returns:
        the string.
        Since:
        3.3.8
      • getCancelString

        public static java.lang.String getCancelString​(java.util.Locale locale)
        Gets the string representing Cancel button.
        Parameters:
        locale - the locale
        Returns:
        the string.
        Since:
        3.3.8
      • getYesString

        public static java.lang.String getYesString​(java.util.Locale locale)
        Gets the string representing Yes button.
        Parameters:
        locale - the locale
        Returns:
        the string.
        Since:
        3.3.8
      • getNoString

        public static java.lang.String getNoString​(java.util.Locale locale)
        Gets the string representing No button.
        Parameters:
        locale - the locale
        Returns:
        the string.
        Since:
        3.3.8
      • getFontMetrics

        public static java.awt.FontMetrics getFontMetrics​(javax.swing.JComponent c,
                                                          java.awt.Graphics g)
        Copied from JDK's SwingUtilities2.java

        Returns the FontMetrics for the current Font of the passed in Graphics. This method is used when a Graphics is available, typically when painting. If a Graphics is not available the JComponent method of the same name should be used.

        Callers should pass in a non-null JComponent, the exception to this is if a JComponent is not readily available at the time of painting.

        This does not necessarily return the FontMetrics from the Graphics.

        Parameters:
        c - JComponent requesting FontMetrics, may be null
        g - Graphics Graphics
      • getFontMetrics

        public static java.awt.FontMetrics getFontMetrics​(javax.swing.JComponent c,
                                                          java.awt.Graphics g,
                                                          java.awt.Font font)
        Copied from JDK's SwingUtilities2.java

        Returns the FontMetrics for the specified Font. This method is used when a Graphics is available, typically when painting. If a Graphics is not available the JComponent method of the same name should be used.

        Callers should pass in a non-null JComponent, the exception to this is if a JComponent is not readily available at the time of painting.

        This does not necessarily return the FontMetrics from the Graphics.

        Parameters:
        c - JComponent requesting FontMetrics, may be null
        c - Graphics Graphics
        font - Font to get FontMetrics for
      • showPopupMenu

        public static void showPopupMenu​(javax.swing.JPopupMenu popup,
                                         java.awt.Component invoker,
                                         int x,
                                         int y)
        Shows the popup menu with the consideration of the invoker's orientation.
        Parameters:
        popup - the popup menu
        invoker - the invoker for the popup menu
        x - the x, usually the x of the mouse clicked position
        y - the y, usually the y of the mouse clicked position