Package com.jidesoft.swing
Class JideSwingUtilities
java.lang.Object
com.jidesoft.swing.JideSwingUtilities
- All Implemented Interfaces:
SwingConstants
A utilities class for Swing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA simple handler used by setRecursively.static interfaceA simple handler used by getRecursively.static interfaceA simple handler used by setRecursively.static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectKey used in client properties to indicate whether or not the component should use aa text.static final StringsetOpaqueRecursively method will make all child components opaque true or false.protected static booleanFields 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdds a separator to the popup menu if there are menu items on it already.static DimensionadjustPreferredScrollableViewportSize(JList list, Dimension defaultViewportSize) This method can be used to fix two JDK bugs.static intbinarySearch(int[] a, int key) Perform a binary search over a sorted array for the given key.static intbinarySearch(int[] a, int key, int start, int end) Perform a binary search over a sorted array for the given key.static <T> intbinarySearch(List<T> a, T key) Perform a binary search over a sorted list for the given key.static <T> intbinarySearch(T[] a, T key) Perform a binary search over a sorted array for the given key.static voidcenterWindow(Window childToCenter) Center the component to it's parent window.static booleancharsEqualIgnoreCase(char a, char b) static voidClears the gradient cache used for fast gradient paintingstatic booleanstatic booleancompositeRequestFocus(Component component) Copied from BasicLookAndFeel as the method is package local.static booleancontainerContainsFocus, does the specified container contain the current focusOwner?static Vectorstatic JPanelcreateBottomPanel(Component object) Create a Panel around a component so that component aligns to bottom.static JPanelcreateCenterPanel(Component object) Create a Panel around a component so that component is right in the middle.static JPanelcreateLabeledComponent(JLabel title, Component component, Object constraint) Creates a container which a label for the component.static JPanelcreateLeftPanel(Component object) Create a Panel around a component so that component aligns to left.static JPanelcreateRightPanel(Component object) Create a Panel around a component so that component aligns to right.static JPanelcreateTableModelModifier(DefaultTableModel tableModel) For internal usage only.static JPanelcreateTopPanel(Component object) Create a Panel around a component so that component aligns to top.Disables the double buffered flag of the component and its children.static voidstatic voidstatic voiddrawImageBorder(Graphics g, ImageIcon img, Rectangle rect, Insets ins, boolean drawCenter) Draws a border based on an image.static voiddrawShadow(Graphics g, Component c, int x, int y, int w, int h) static voiddrawString(JComponent c, Graphics g, String text, int x, int y) static voiddrawStringUnderlineCharAt(JComponent c, Graphics g, String text, int underlinedIndex, int x, int y) static booleandrawTextAntialiased(boolean aaText) Returns whether or not text should be drawn anti-aliased.Enables the double buffered flag of the component and its children.static voidensureRowVisible(JTable table, int row) To make sure the row is visible.static booleanequals(CharSequence s1, CharSequence s2, boolean caseSensitive) static booleanChecks if the two objects equal.static booleanChecks if the two objects equal.static booleanChecks if the two objects equal.static voidfillGradient(Graphics2D g2d, Shape s, Color startColor, Color endColor, boolean isVertical) Fills a gradient using the startColor and endColor specified.static voidfillGradient(Graphics g, Rectangle rect, int orientation) static voidfillNormalGradient(Graphics2D g2d, Shape s, Color startColor, Color endColor, boolean isVertical) static voidfillSingleGradient(Graphics g, Rectangle rect, int orientation) static voidfillSingleGradient(Graphics g, Rectangle rect, int orientation, int level) static intfindDisplayedMnemonicIndex(String text, int mnemonic) static ComponentfindFirstComponentByClass(Container c, Class<?> clazz) Gets the first component inside the specified container that has the specified class.static ComponentfindFirstComponentByName(Container c, String name) Gets the first component inside the specified container that has the specified name.static ComponentfindSomethingFocusable(Container container) Find some subcomponent of the specified container that will accept focus.static ObjectgetBoldFont(Toolkit toolkit, UIDefaults table) static int[]static intstatic StringgetCancelString(Locale locale) Gets the string representing Cancel button.static intgetComponentIndex(Container container, Component c) Get the index of the component in the container.static ObjectgetControlFont(Toolkit toolkit, UIDefaults table) static ObjectgetControlFont(Toolkit toolkit, UIDefaults table, String defaultUIDefault) static floatstatic ComponentgetDescendantOfClass(Class c, Container container) Gets the first occurrence of the component with specified type in the container.static BufferedImagegetFasterScaledInstance(BufferedImage img, int targetWidth, int targetHeight, Object hint, boolean progressiveBilinear) Convenience method that returns a scaled instance of the provided BufferedImage.static ComponentgetFirstChildOf(Class<?> clazz, Component c) Gets the first child of the component that is the specified type.static JComponentgetFirstJComponent(RootPaneContainer rootPaneContainer) Gets the first JComponent from the RootPaneContainer.static intstatic FontMetricsgetFontMetrics(JComponent c, Graphics g) Copied from JDK's SwingUtilities2.javastatic FontMetricsgetFontMetrics(JComponent c, Graphics g, Font font) Copied from JDK's SwingUtilities2.javastatic FrameGets the top level Frame of the component.static PaintgetLinearGradientPaint(float startX, float startY, float endX, float endY, float[] fractions, Color[] colors) Gets the LinearGradientPaint.static intgetLineHeight(Component c, int defaultHeight) Gets the line height for the font for the componentstatic ObjectgetMenuFont(Toolkit toolkit, UIDefaults table) static StringgetNoString(Locale locale) Gets the string representing No button.static StringgetOKString(Locale locale) Gets the string representing OK button.static intgetOrientationOf(Component component) static JRootPaneIf c is a JRootPane descendant return its outermost JRootPane ancestor.static DimensiongetPreferredButtonSize(AbstractButton b, int textIconGap, boolean isHorizontal) static PaintgetRadialGradientPaint(float cx, float cy, float radius, float[] fractions, Color[] colors) Gets the RadialGradientPaint.static PaintgetRadialGradientPaint(Point2D point, float radius, float[] fractions, Color[] colors) Gets the RadialGradientPaint.static ComponentgetRecursively(Component c, JideSwingUtilities.GetHandler handler) Gets to a child of a component recursively based on certain condition.static ComponentgetScrollPane(Component innerComponent) Gets the scroll pane around the component.static WindowGets the top modal dialog of current window.static ChangeListenerstatic WindowgetWindowForComponent(Component parentComponent) Gets the top level Dialog or Frame of the component.static StringgetYesString(Locale locale) Gets the string representing Yes button.static voidglobalCenterWindow(Window childToCenter) Center the window to the whole screen.static voidIgnore the exception.static voidinsertKeyListener(Component component, KeyListener l, int index) Inserts the key listener at the particular index in the listeners' chain.static voidinsertMouseListener(Component component, MouseListener l, int index) Inserts the mouse listener at the particular index in the listeners' chain.static voidinsertMouseMotionListener(Component component, MouseMotionListener l, int index) Inserts the mouse motion listener at the particular index in the listeners' chain.static voidinsertPropertyChangeListener(Component component, PropertyChangeListener l, String propertyName, int index) Inserts the property change listener at the particular index in the listeners' chain.static voidinsertPropertyChangeListener(KeyboardFocusManager manager, PropertyChangeListener l, String propertyName, int index) Inserts the property change listener at the particular index in the listeners' chain.static voidinsertTableModelListener(TableModel model, TableModelListener l, int index) Inserts the table model listener at the particular index in the listeners' chain.static voidinstallBorder(JComponent c, Border defaultBorder) static voidinstallColors(Component c, Color background, Color foreground) static voidinstallColorsAndFont(Component c, Color background, Color foreground, Font font) static voidinstallFont(Component c, Font font) static voidInvalidate and doLayout on the component and all its child components if any.static booleanisAncestorOfFocusOwner(Component component) static booleanisFixedWidthFont(String fontName, Component component) Checks if the font specified by the font name is fixed width font.static booleanisKeyListenerRegistered(Component component, KeyListener l) Checks if the key listener is already registered on the component.static booleanisListenerRegistered(Component component, Class t, EventListener l) Checks if the listener is always registered to the Component to avoid duplicated registration of the same listenerstatic booleanisListenerRegistered(EventListenerList list, Class t, EventListener l) Checks if the listener is always registered to the EventListenerList to avoid duplicated registration of the same listenerstatic booleanisMenuShortcutKeyDown(ActionEvent event) Checks if the ctrl key is pressed.static booleanisMenuShortcutKeyDown(InputEvent event) Checks if the ctrl key is pressed.static booleanisMouseListenerRegistered(Component component, MouseListener l) Checks if the mouse listener is already registered on the component.static booleanisMouseMotionListenerRegistered(Component component, MouseMotionListener l) Checks if the mouse motion listener is already registered on the component.static booleanChecks if the property change listener is already registered on the component.static booleanisPropertyChangeListenerRegistered(Component component, String propertyName, PropertyChangeListener l) Checks if the property change listener is already registered on the component.static StringlayoutCompoundLabel(FontMetrics fm, String text, Icon icon, boolean isHorizontal, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, 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 StringlayoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon icon, boolean isHorizontal, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, 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 voidpaintArrow(Graphics g, Color color, int startX, int startY, int width, int orientation) Paints an arrow shape.static voidpaintArrow(JComponent c, Graphics g, Color color, int startX, int startY, int width, int orientation) Paints an arrow shape.static voidpaintBackground(Graphics2D g2d, Rectangle rect, Color border, Paint paint) static voidpaintBackground(Graphics g, Rectangle rect, Color border, Color bk) static voidpaintCross(Graphics g, Color color, int centerX, int centerY, int size, int width) Paints a cross shape.static booleanThere are four standard tests which determine if Swing will be able to request focus for a component.static voidPrints out the message of the exception.static voidstatic voidputClientPropertyRecursively(Component c, String clientProperty, Object value) Calls putClientProperty method recursively on component and its child components as long as it is JComponent.static voidregisterTabKey(Container container) Register the tab key with the container.static voidremoveExtraSeparators(JPopupMenu popup) Removes extra separators, if any.static voidremoveFromParentWithFocusTransfer(Component component) The semantics in AWT of hiding a component, removing a component, and reparenting a component are inconsistent with respect to focus.static voidrestoreAntialiasing(Component c, Graphics g, Object oldHints) Restores the old setting for text anti-alias.static voidrestoreDoubleBuffered(Component c, Map<Component, Boolean> map) Restores the double buffered flag of the component and its children.static voidrestoreShapeAntialiasing(Graphics g, Object oldHints) Restores the old setting for shape anti-alias.static voidretargetMouseEvent(int id, MouseEvent e, Component target) static voidstatic voidSets the bounds.static voidSets the bounds.static voidsetChildrenOrientationOf(Container c, int orientation) static voidsetComponentTransparent(JComponent component) Sets the text component transparent.static voidsetEnabledRecursively(Component c, boolean enabled) Calls setEnabled method recursively on component.static voidsetLocaleRecursively(Component c, Locale locale) Sets the locale recursively on the component and all its child components if any.static voidsetOpaqueRecursively(Component c, boolean opaque) Calls setOpaque method recursively on each component except for JButton, JComboBox and JTextComponent.static voidsetOrientationOf(Component component, int orientation) static voidsetRecursively(Component c, JideSwingUtilities.Handler handler) Calls the handler recursively on a component.static voidsetRequestFocusEnabledRecursively(Component c, boolean enabled) Calls setRequestFocusEnabled method recursively on component.static voidsetTextComponentTransparent(JComponent component) Deprecated.static ObjectSetups the graphics to draw text using anti-alias.static ObjectSetups the graphics to draw shape using anti-alias.static voidsetWindowOpacity(Window window, float opacity) Sets the Window opacity using AWTUtilities.setWindowOpacity on JDK6u10 and later.static voidsetWindowOpaque(Window window, boolean opaque) Sets the Window opaque using AWTUtilities.setWindowOpaque on JDK6u10 and later.static voidsetWindowShape(Window window, Shape shape) Sets the Window shape using AWTUtilities.setWindowOpacity on JDK6u10 and later.static booleanIn JDK1.4, it uses a wrong font for Swing component in Windows Linvalid input: '&F' which is actually one big reason for people to think Swing application ugly.static voidshowPopupMenu(JPopupMenu popup, Component invoker, int x, int y) Shows the popup menu with the consideration of the invoker's orientation.static voidsynchronizeKeyboardActions(JComponent sourceComponent, JComponent targetComponent, KeyStroke[] keyStrokes, int condition) Registers all actions registered on the source component and registered them on the target component at the specified condition.static voidsynchronizeView(JViewport masterViewport, JViewport slaveViewport, int orientation) Synchronizes the two viewports.static voidThrows the exception.static voidThrows the InvocationTargetException.static voidtoggleRTLnLTR(Component topContainer) Toggles between RTL and LTR.static chartoLowerCase(char a) static chartoUpperCase(char a) static voidFor internal usage only.static voidtraceFocus(boolean useBorders) For internal usage only.static voidunsynchronizeView(JViewport masterViewport, JViewport slaveViewport) Un-synchronizes the two viewport.
-
Field Details
-
AA_TEXT_PROPERTY_KEY
Key used in client properties to indicate whether or not the component should use aa text. -
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:
-
tracingFocus
protected static boolean tracingFocus
-
-
Constructor Details
-
JideSwingUtilities
public JideSwingUtilities()
-
-
Method Details
-
createLeftPanel
Create a Panel around a component so that component aligns to left.- Parameters:
object- the component- Returns:
- a Panel
-
createRightPanel
Create a Panel around a component so that component aligns to right.- Parameters:
object- the component- Returns:
- a Panel
-
createTopPanel
Create a Panel around a component so that component aligns to top.- Parameters:
object- the component- Returns:
- a Panel
-
createBottomPanel
Create a Panel around a component so that component aligns to bottom.- Parameters:
object- the component- Returns:
- a Panel
-
createCenterPanel
Create a Panel around a component so that component is right in the middle.- Parameters:
object- the component- Returns:
- a Panel
-
createLabeledComponent
Creates a container which a label for the component.- Parameters:
title- the labelcomponent- the componentconstraint- 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
Center the component to it's parent window.- Parameters:
childToCenter- the parent window
-
globalCenterWindow
Center the window to the whole screen.- Parameters:
childToCenter- the parent window
-
paintArrow
public static void paintArrow(Graphics g, Color color, int startX, int startY, int width, int orientation) Paints an arrow shape.- Parameters:
g- the graphics instancecolor- colorstartX- start XstartY- start Ywidth- widthorientation- horizontal or vertical
-
paintArrow
public static void paintArrow(JComponent c, Graphics g, Color color, int startX, int startY, int width, int orientation) Paints an arrow shape.- Parameters:
c- the componentg- the graphics instancecolor- colorstartX- start XstartY- start Ywidth- widthorientation- horizontal or vertical
-
paintCross
public static void paintCross(Graphics g, Color color, int centerX, int centerY, int size, int width) Paints a cross shape.- Parameters:
g- the graphics instancecolor- colorcenterX- center XcenterY- center Ysize- sizewidth- width
-
getFrame
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
Toggles between RTL and LTR.- Parameters:
topContainer- the component
-
synchronizeView
public static void synchronizeView(JViewport masterViewport, 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 viewportslaveViewport- the slave viewportorientation- the orientation. It could be either SwingConstants.HORIZONTAL or SwingConstants.VERTICAL.
-
unsynchronizeView
Un-synchronizes the two viewport.- Parameters:
masterViewport- the master viewportslaveViewport- the slave viewport
-
getButtonState
-
getButtonState
-
equals
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 useo1.equals(o2)to compare. If none of the above conditions match, we return false.- Parameters:
o1- the first object to compareo2- the second object to compare- Returns:
- true if the two objects are equal. Otherwise false.
-
equals
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 useo1.equals(o2)to compare. If none of the above conditions match, we return false.- Parameters:
o1- the first object to compareo2- the second object to compareconsiderArrayOrList- 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(Object o1, 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 useo1.equals(o2)to compare. If none of the above conditions match, we return false.- Parameters:
o1- the first object to compareo2- the second object to compareconsiderArrayOrList- 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
-
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 BufferedImage getFasterScaledInstance(BufferedImage img, int targetWidth, int targetHeight, Object hint, boolean progressiveBilinear) Convenience method that returns a scaled instance of the provided BufferedImage.- Parameters:
img- the original image to be scaledtargetWidth- the desired width of the scaled instance, in pixelstargetHeight- the desired height of the scaled instance, in pixelshint- 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 Linvalid input: '&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 Linvalid input: '&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 Linvalid input: '&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 Linvalid input: '&F' should use system font.
-
printUIDefaults
public static void printUIDefaults() -
setRecursively
Calls the handler recursively on a component.- Parameters:
c- componenthandler- handler to be called
-
findFirstComponentByName
Gets the first component inside the specified container that has the specified name.- Parameters:
c- the containername- the name of the component- Returns:
- the component. Null if not found.
-
findFirstComponentByClass
Gets the first component inside the specified container that has the specified class.- Parameters:
c- the containerclazz- the class of the component- Returns:
- the component. Null if not found.
-
getRecursively
Gets to a child of a component recursively based on certain condition.- Parameters:
c- componenthandler- handler to be called- Returns:
- the component that matches the condition specified in GetHandler.
-
setEnabledRecursively
Calls setEnabled method recursively on component.Componentc is usually aContainer- Parameters:
c- componentenabled- true if enable; false otherwise
-
putClientPropertyRecursively
Calls putClientProperty method recursively on component and its child components as long as it is JComponent.- Parameters:
c- componentclientProperty- the client property namevalue- the value for the client property
-
setRequestFocusEnabledRecursively
Calls setRequestFocusEnabled method recursively on component.Componentc is usually aContainer- Parameters:
c- componentenabled- true if setRequestFocusEnabled to true; false otherwise
-
setOpaqueRecursively
Calls setOpaque method recursively on each component except for JButton, JComboBox and JTextComponent.Componentc is usually aContainer. 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- componentopaque- true if setOpaque to true; false otherwise
-
getPreferredButtonSize
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap, boolean isHorizontal) -
layoutCompoundLabel
public static String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon icon, boolean isHorizontal, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, 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 componentfm- the font metricstext- the texticon- the iconisHorizontal- the flag indicating horizontal or verticalverticalAlignment- vertical alignment modelhorizontalAlignment- horizontal alignment modelverticalTextPosition- vertical text positionhorizontalTextPosition- horizontal text positionviewR- view rectangleiconR- icon rectangletextR- text rectangletextIconGap- the gap between the text and the gap- Returns:
- the string after layout.
-
layoutCompoundLabel
public static String layoutCompoundLabel(FontMetrics fm, String text, Icon icon, boolean isHorizontal, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, 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 metricstext- the text to layouticon- the icon to layoutisHorizontal- if the layout is horizontalverticalAlignment- the vertical alignmenthorizontalAlignment- the horizontal alignmentverticalTextPosition- the vertical text positionhorizontalTextPosition- the horizontal text positionviewR- the view rectangleiconR- the icon rectangletextR- the text rectangletextIconGap- the gap between the text and the icon- Returns:
- the string after layout.
-
getOrientationOf
-
setOrientationOf
-
setChildrenOrientationOf
-
disableDoubleBuffered
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 usingrestoreDoubleBuffered(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
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 usingrestoreDoubleBuffered(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
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
-
paintBackground
-
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(JComponent c, Graphics g, String text, int underlinedIndex, int x, int y) -
drawString
-
setupAntialiasing
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 componentg- 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
Restores the old setting for text anti-alias.- Parameters:
c-g-oldHints- the value returned fromsetupAntialiasing(java.awt.Component, java.awt.Graphics).
-
setupShapeAntialiasing
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
Restores the old setting for shape anti-alias.- Parameters:
g-oldHints- the value returned fromsetupShapeAntialiasing(java.awt.Graphics).
-
drawGrip
-
drawGrip
-
registerTabKey
Register the tab key with the container.- Parameters:
container-
-
fillGradient
-
fillSingleGradient
-
fillSingleGradient
-
getRadialGradientPaint
public static Paint getRadialGradientPaint(Point2D point, float radius, float[] fractions, 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 Paint getRadialGradientPaint(float cx, float cy, float radius, float[] fractions, 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 Paint getLinearGradientPaint(float startX, float startY, float endX, float endY, float[] fractions, 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
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
-
installColorsAndFont
-
installFont
-
installColors
-
installBorder
-
fillNormalGradient
public static void fillNormalGradient(Graphics2D g2d, Shape s, Color startColor, Color endColor, boolean isVertical) -
fillGradient
public static void fillGradient(Graphics2D g2d, Shape s, Color startColor, 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
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
For internal usage only. -
findSomethingFocusable
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
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
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
Prints out the message of the exception.- Parameters:
e-
-
throwException
Throws the exception. If the exception is RuntimeException, just throw it. Otherwise, wrap it in RuntimeException and throw it.- Parameters:
e-
-
throwInvocationTargetException
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
-
getDescendantOfClass
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
-
getControlFont
-
getControlFont
-
getBoldFont
-
drawShadow
-
drawImageBorder
public static void drawImageBorder(Graphics g, ImageIcon img, Rectangle rect, 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
Copied from BasicLookAndFeel as the method is package local.- Parameters:
component-- Returns:
- if request focus is success or not.
-
isAncestorOfFocusOwner
-
getWindowForComponent
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:
HeadlessException
-
isKeyListenerRegistered
Checks if the key listener is already registered on the component.- Parameters:
component- the componentl- the listener- Returns:
- true if already registered. Otherwise false.
-
insertKeyListener
Inserts the key listener at the particular index in the listeners' chain.- Parameters:
component-l-index-
-
insertTableModelListener
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 AbstractTableModell- the TableModelListener to be insertedindex- the index.
-
insertPropertyChangeListener
public static void insertPropertyChangeListener(Component component, PropertyChangeListener l, 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 insertedpropertyName- the name of the property. Could be null.index- the index to be inserted
-
insertPropertyChangeListener
public static void insertPropertyChangeListener(KeyboardFocusManager manager, PropertyChangeListener l, 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 insertedpropertyName- the name of the property. Could be null.index- the index to be inserted
-
isPropertyChangeListenerRegistered
public static boolean isPropertyChangeListenerRegistered(Component component, PropertyChangeListener l) Checks if the property change listener is already registered on the component.- Parameters:
component- the componentl- the listener- Returns:
- true if already registered. Otherwise false.
-
isPropertyChangeListenerRegistered
public static boolean isPropertyChangeListenerRegistered(Component component, String propertyName, PropertyChangeListener l) Checks if the property change listener is already registered on the component.- Parameters:
component- the componentpropertyName- the property namel- the listener- Returns:
- true if already registered. Otherwise false.
-
isMouseListenerRegistered
Checks if the mouse listener is already registered on the component.- Parameters:
component- the componentl- the listener- Returns:
- true if already registered. Otherwise false.
-
insertMouseListener
Inserts the mouse listener at the particular index in the listeners' chain.- Parameters:
component-l-index-
-
isMouseMotionListenerRegistered
Checks if the mouse motion listener is already registered on the component.- Parameters:
component- the componentl- the listener- Returns:
- true if already registered. Otherwise false.
-
insertMouseMotionListener
Inserts the mouse motion listener at the particular index in the listeners' chain.- Parameters:
component-l-index-
-
getScrollPane
Gets the scroll pane around the component.- Parameters:
innerComponent-- Returns:
- the scroll pane. Null if the component is not in any JScrollPane.
-
isListenerRegistered
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
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
Gets the first child of the component that is the specified type.- Parameters:
clazz- the type of the component to look forc- the component- Returns:
- the first child of the component that is the specified type.
-
getComponentIndex
Get the index of the component in the container. It will return -1 if c's parent is not container.- Parameters:
container- the containerc- the component- Returns:
- the index
-
convertDefaultComboBoxModelToVector
-
ensureRowVisible
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
-
getOutermostRootPane
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
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 namecomponent- the component where the font will be displayed.- Returns:
- true if the font is fixed width. Otherwise false.
-
setLocaleRecursively
Sets the locale recursively on the component and all its child components if any.- Parameters:
c- the componentlocale- the new locales.
-
setBounds
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 boundsbounds- the bounds.
-
setBounds
public static void setBounds(Container container, 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 boundsx- the x of the boundsy- the y of the boundswidth- the the height of the bounds. of the bounds.height- the height of the bounds.
-
invalidateRecursively
Invalidate and doLayout on the component and all its child components if any.- Parameters:
c- the component
-
synchronizeKeyboardActions
public static void synchronizeKeyboardActions(JComponent sourceComponent, JComponent targetComponent, 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 keystrokescondition- the condition which will be used inJComponent.registerKeyboardAction(java.awt.event.ActionListener, javax.swing.KeyStroke, int)as the last parameter.
-
getFirstJComponent
Gets the first JComponent from the RootPaneContainer.- Parameters:
rootPaneContainer- a rootPaneContainer- Returns:
- the first JComponent from the rootPaneContainer's content pane.
-
adjustPreferredScrollableViewportSize
public static Dimension adjustPreferredScrollableViewportSize(JList list, 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 JListdefaultViewportSize- the default viewport size from JList#getPreferredScrollableViewportSize().- Returns:
- the adjusted size.
-
removeFromParentWithFocusTransfer
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
Gets the line height for the font for the component- Parameters:
c- the componentdefaultHeight- 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
Adds a separator to the popup menu if there are menu items on it already.- Parameters:
popup- the popup menu.
-
removeExtraSeparators
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.replaced bysetComponentTransparent(javax.swing.JComponent).Sets the text component transparent. It will call setOpaque(false) and also set client property for certain Linvalid input: '&Fs' in case the Linvalid input: '&F' doesn't respect the opaque flag.- Parameters:
component- the text component to be set to transparent.
-
setComponentTransparent
Sets the text component transparent. It will call setOpaque(false) and also set client property for certain Linvalid input: '&Fs' in case the Linvalid input: '&F' doesn't respect the opaque flag.- Parameters:
component- the text component to be set to transparent.
-
binarySearch
Perform a binary search over a sorted list for the given key.- Parameters:
a- the array to searchkey- 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 searchkey- 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 searchkey- 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 searchkey- the key to search forstart- the start index to search inclusiveend- 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
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
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
-
setWindowOpaque
Sets the Window opaque using AWTUtilities.setWindowOpaque on JDK6u10 and later.- Parameters:
window- the Windowopaque- true or false
-
setWindowOpacity
Sets the Window opacity using AWTUtilities.setWindowOpacity on JDK6u10 and later.- Parameters:
window- the Windowopacity- the opacity
-
setWindowShape
Sets the Window shape using AWTUtilities.setWindowOpacity on JDK6u10 and later.- Parameters:
window- the Windowshape- the shape
-
getOKString
Gets the string representing OK button.- Parameters:
locale- the locale- Returns:
- the string.
- Since:
- 3.3.8
-
getCancelString
Gets the string representing Cancel button.- Parameters:
locale- the locale- Returns:
- the string.
- Since:
- 3.3.8
-
getYesString
Gets the string representing Yes button.- Parameters:
locale- the locale- Returns:
- the string.
- Since:
- 3.3.8
-
getNoString
Gets the string representing No button.- Parameters:
locale- the locale- Returns:
- the string.
- Since:
- 3.3.8
-
getFontMetrics
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 nullg- Graphics Graphics
-
getFontMetrics
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 nullfont- Font to get FontMetrics forc- Graphics Graphics
-
showPopupMenu
Shows the popup menu with the consideration of the invoker's orientation.- Parameters:
popup- the popup menuinvoker- the invoker for the popup menux- the x, usually the x of the mouse clicked positiony- the y, usually the y of the mouse clicked position
-
setComponentTransparent(javax.swing.JComponent).