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 interface
A simple handler used by setRecursively.static interface
A simple handler used by getRecursively.static interface
A simple handler used by setRecursively.static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Object
Key used in client properties to indicate whether or not the component should use aa text.static final String
setOpaqueRecursively method will make all child components opaque true or false.protected static boolean
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Adds a separator to the popup menu if there are menu items on it already.static Dimension
adjustPreferredScrollableViewportSize
(JList list, 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
(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
(Window childToCenter) Center the component to it's parent window.static boolean
charsEqualIgnoreCase
(char a, char b) static void
Clears the gradient cache used for fast gradient paintingstatic boolean
static boolean
compositeRequestFocus
(Component component) Copied from BasicLookAndFeel as the method is package local.static boolean
containerContainsFocus, does the specified container contain the current focusOwner?static Vector
static JPanel
createBottomPanel
(Component object) Create a Panel around a component so that component aligns to bottom.static JPanel
createCenterPanel
(Component object) Create a Panel around a component so that component is right in the middle.static JPanel
createLabeledComponent
(JLabel title, Component component, Object constraint) Creates a container which a label for the component.static JPanel
createLeftPanel
(Component object) Create a Panel around a component so that component aligns to left.static JPanel
createRightPanel
(Component object) Create a Panel around a component so that component aligns to right.static JPanel
createTableModelModifier
(DefaultTableModel tableModel) For internal usage only.static JPanel
createTopPanel
(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 void
static void
static void
drawImageBorder
(Graphics g, ImageIcon img, Rectangle rect, Insets ins, boolean drawCenter) Draws a border based on an image.static void
drawShadow
(Graphics g, Component c, int x, int y, int w, int h) static void
drawString
(JComponent c, Graphics g, String text, int x, int y) static void
drawStringUnderlineCharAt
(JComponent c, Graphics g, String text, int underlinedIndex, int x, int y) static boolean
drawTextAntialiased
(boolean aaText) Returns whether or not text should be drawn anti-aliased.Enables the double buffered flag of the component and its children.static void
ensureRowVisible
(JTable table, int row) To make sure the row is visible.static boolean
equals
(CharSequence s1, CharSequence s2, boolean caseSensitive) static boolean
Checks if the two objects equal.static boolean
Checks if the two objects equal.static boolean
Checks if the two objects equal.static void
fillGradient
(Graphics2D g2d, Shape s, Color startColor, Color endColor, boolean isVertical) Fills a gradient using the startColor and endColor specified.static void
fillGradient
(Graphics g, Rectangle rect, int orientation) static void
fillNormalGradient
(Graphics2D g2d, Shape s, Color startColor, Color endColor, boolean isVertical) static void
fillSingleGradient
(Graphics g, Rectangle rect, int orientation) static void
fillSingleGradient
(Graphics g, Rectangle rect, int orientation, int level) static int
findDisplayedMnemonicIndex
(String text, int mnemonic) static Component
findFirstComponentByClass
(Container c, Class<?> clazz) Gets the first component inside the specified container that has the specified class.static Component
findFirstComponentByName
(Container c, String name) Gets the first component inside the specified container that has the specified name.static Component
findSomethingFocusable
(Container container) Find some subcomponent of the specified container that will accept focus.static Object
getBoldFont
(Toolkit toolkit, UIDefaults table) static int[]
static int
static String
getCancelString
(Locale locale) Gets the string representing Cancel button.static int
getComponentIndex
(Container container, Component c) Get the index of the component in the container.static Object
getControlFont
(Toolkit toolkit, UIDefaults table) static Object
getControlFont
(Toolkit toolkit, UIDefaults table, String defaultUIDefault) static float
static Component
getDescendantOfClass
(Class c, Container container) Gets the first occurrence of the component with specified type in the container.static BufferedImage
getFasterScaledInstance
(BufferedImage img, int targetWidth, int targetHeight, Object hint, boolean progressiveBilinear) Convenience method that returns a scaled instance of the provided BufferedImage.static Component
getFirstChildOf
(Class<?> clazz, Component c) Gets the first child of the component that is the specified type.static JComponent
getFirstJComponent
(RootPaneContainer rootPaneContainer) Gets the first JComponent from the RootPaneContainer.static int
static FontMetrics
getFontMetrics
(JComponent c, Graphics g) Copied from JDK's SwingUtilities2.javastatic FontMetrics
getFontMetrics
(JComponent c, Graphics g, Font font) Copied from JDK's SwingUtilities2.javastatic Frame
Gets the top level Frame of the component.static Paint
getLinearGradientPaint
(float startX, float startY, float endX, float endY, float[] fractions, Color[] colors) Gets the LinearGradientPaint.static int
getLineHeight
(Component c, int defaultHeight) Gets the line height for the font for the componentstatic Object
getMenuFont
(Toolkit toolkit, UIDefaults table) static String
getNoString
(Locale locale) Gets the string representing No button.static String
getOKString
(Locale locale) Gets the string representing OK button.static int
getOrientationOf
(Component component) static JRootPane
If c is a JRootPane descendant return its outermost JRootPane ancestor.static Dimension
getPreferredButtonSize
(AbstractButton b, int textIconGap, boolean isHorizontal) static Paint
getRadialGradientPaint
(float cx, float cy, float radius, float[] fractions, Color[] colors) Gets the RadialGradientPaint.static Paint
getRadialGradientPaint
(Point2D point, float radius, float[] fractions, Color[] colors) Gets the RadialGradientPaint.static Component
getRecursively
(Component c, JideSwingUtilities.GetHandler handler) Gets to a child of a component recursively based on certain condition.static Component
getScrollPane
(Component innerComponent) Gets the scroll pane around the component.static Window
Gets the top modal dialog of current window.static ChangeListener
static Window
getWindowForComponent
(Component parentComponent) Gets the top level Dialog or Frame of the component.static String
getYesString
(Locale locale) Gets the string representing Yes button.static void
globalCenterWindow
(Window childToCenter) Center the window to the whole screen.static void
Ignore the exception.static void
insertKeyListener
(Component component, KeyListener l, int index) Inserts the key listener at the particular index in the listeners' chain.static void
insertMouseListener
(Component component, MouseListener l, int index) Inserts the mouse listener at the particular index in the listeners' chain.static void
insertMouseMotionListener
(Component component, MouseMotionListener l, int index) Inserts the mouse motion listener at the particular index in the listeners' chain.static void
insertPropertyChangeListener
(Component component, PropertyChangeListener l, String propertyName, int index) Inserts the property change listener at the particular index in the listeners' chain.static void
insertPropertyChangeListener
(KeyboardFocusManager manager, PropertyChangeListener l, String propertyName, int index) Inserts the property change listener at the particular index in the listeners' chain.static void
insertTableModelListener
(TableModel model, TableModelListener l, int index) Inserts the table model listener at the particular index in the listeners' chain.static void
installBorder
(JComponent c, Border defaultBorder) static void
installColors
(Component c, Color background, Color foreground) static void
installColorsAndFont
(Component c, Color background, Color foreground, Font font) static void
installFont
(Component c, Font font) static void
Invalidate and doLayout on the component and all its child components if any.static boolean
isAncestorOfFocusOwner
(Component component) static boolean
isFixedWidthFont
(String fontName, Component component) Checks if the font specified by the font name is fixed width font.static boolean
isKeyListenerRegistered
(Component component, KeyListener l) Checks if the key listener is already registered on the component.static boolean
isListenerRegistered
(Component component, Class t, EventListener l) Checks if the listener is always registered to the Component to avoid duplicated registration of the same listenerstatic boolean
isListenerRegistered
(EventListenerList list, Class t, EventListener l) Checks if the listener is always registered to the EventListenerList to avoid duplicated registration of the same listenerstatic boolean
isMenuShortcutKeyDown
(ActionEvent event) Checks if the ctrl key is pressed.static boolean
isMenuShortcutKeyDown
(InputEvent event) Checks if the ctrl key is pressed.static boolean
isMouseListenerRegistered
(Component component, MouseListener l) Checks if the mouse listener is already registered on the component.static boolean
isMouseMotionListenerRegistered
(Component component, MouseMotionListener l) Checks if the mouse motion listener is already registered on the component.static boolean
Checks if the property change listener is already registered on the component.static boolean
isPropertyChangeListenerRegistered
(Component component, String propertyName, PropertyChangeListener l) Checks if the property change listener is already registered on the component.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.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.static void
paintArrow
(Graphics g, Color color, int startX, int startY, int width, int orientation) Paints an arrow shape.static void
paintArrow
(JComponent c, Graphics g, Color color, int startX, int startY, int width, int orientation) Paints an arrow shape.static void
paintBackground
(Graphics2D g2d, Rectangle rect, Color border, Paint paint) static void
paintBackground
(Graphics g, Rectangle rect, Color border, Color bk) static void
paintCross
(Graphics g, Color color, int centerX, int centerY, int size, int width) Paints a cross shape.static boolean
There are four standard tests which determine if Swing will be able to request focus for a component.static void
Prints out the message of the exception.static void
static void
putClientPropertyRecursively
(Component c, String clientProperty, Object value) Calls putClientProperty method recursively on component and its child components as long as it is JComponent.static void
registerTabKey
(Container container) Register the tab key with the container.static void
removeExtraSeparators
(JPopupMenu popup) Removes extra separators, if any.static void
removeFromParentWithFocusTransfer
(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
(Component c, Graphics g, Object oldHints) Restores the old setting for text anti-alias.static void
restoreDoubleBuffered
(Component c, Map<Component, Boolean> map) Restores the double buffered flag of the component and its children.static void
restoreShapeAntialiasing
(Graphics g, Object oldHints) Restores the old setting for shape anti-alias.static void
retargetMouseEvent
(int id, MouseEvent e, Component target) static void
static void
Sets the bounds.static void
Sets the bounds.static void
setChildrenOrientationOf
(Container c, int orientation) static void
setComponentTransparent
(JComponent component) Sets the text component transparent.static void
setEnabledRecursively
(Component c, boolean enabled) Calls setEnabled method recursively on component.static void
setLocaleRecursively
(Component c, Locale locale) Sets the locale recursively on the component and all its child components if any.static void
setOpaqueRecursively
(Component c, boolean opaque) Calls setOpaque method recursively on each component except for JButton, JComboBox and JTextComponent.static void
setOrientationOf
(Component component, int orientation) static void
setRecursively
(Component c, JideSwingUtilities.Handler handler) Calls the handler recursively on a component.static void
setRequestFocusEnabledRecursively
(Component c, boolean enabled) Calls setRequestFocusEnabled method recursively on component.static void
setTextComponentTransparent
(JComponent component) Deprecated.static Object
Setups the graphics to draw text using anti-alias.static Object
Setups the graphics to draw shape using anti-alias.static void
setWindowOpacity
(Window window, float opacity) Sets the Window opacity using AWTUtilities.setWindowOpacity on JDK6u10 and later.static void
setWindowOpaque
(Window window, boolean opaque) Sets the Window opaque using AWTUtilities.setWindowOpaque on JDK6u10 and later.static void
setWindowShape
(Window window, Shape shape) Sets the Window shape using AWTUtilities.setWindowOpacity on JDK6u10 and later.static boolean
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
(JPopupMenu popup, Component invoker, int x, int y) Shows the popup menu with the consideration of the invoker's orientation.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.static void
synchronizeView
(JViewport masterViewport, JViewport slaveViewport, int orientation) Synchronizes the two viewports.static void
Throws the exception.static void
Throws the InvocationTargetException.static void
toggleRTLnLTR
(Component topContainer) Toggles between RTL and LTR.static char
toLowerCase
(char a) static char
toUpperCase
(char a) static void
For internal usage only.static void
traceFocus
(boolean useBorders) For internal usage only.static void
unsynchronizeView
(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 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
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.Component
c 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.Component
c 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.Component
c 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 L&Fs in case the L&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 L&Fs in case the L&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 nullc
- Graphics Graphicsfont
- Font to get FontMetrics for
-
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)
.