Java Utililty Methods JComponent Container

List of utility methods to do JComponent Container

Description

The list of methods to do JComponent Container are organized into topic(s).

Method

intgetComponentState(JComponent c)
get Component State
if (c.isEnabled()) {
    if (c.isFocusOwner()) {
        return SynthConstants.ENABLED | SynthConstants.FOCUSED;
    return SynthConstants.ENABLED;
return SynthConstants.DISABLED;
DataFlavor[]getDataFlavors(JComponent component)
get Data Flavors
return (DataFlavor[]) component.getClientProperty(FLAVORS_CLIENT_PROPERTY);
ComponentgetDeepestEmptyComponentAt(JComponent parent, Point location)
get Deepest Empty Component At
int size = parent.getComponentCount();
for (int i = 0; i < size; i++) {
    Component child = parent.getComponent(i);
    if (child.isShowing()) {
        if (child.getWidth() < EMPTY_COMPONENT_SIZE || child.getHeight() < EMPTY_COMPONENT_SIZE) {
            Point childLocation = child.getLocationOnScreen();
            Rectangle bounds = new Rectangle();
            bounds.x = childLocation.x;
...
ComponentgetFirstChildComponentOfType(Component component, Class childComponentType)
Retrieves the first contained component of a certain type.
if (childComponentType.isAssignableFrom(component.getClass())) {
    return component;
if (component instanceof Container) {
    Component[] children = ((Container) component).getComponents();
    for (Component child : children) {
        Component childResult = getFirstChildComponentOfType(child, childComponentType);
        if (childResult != null) {
...
ComponentgetGlassPane(JComponent comp)
get Glass Pane
Container container = comp.getTopLevelAncestor();
if (container instanceof JFrame) {
    JFrame frame = (JFrame) container;
    return frame.getGlassPane();
} else if (container instanceof JDialog) {
    JDialog dialog = (JDialog) container;
    return dialog.getGlassPane();
} else {
...
ObjectgetGtkStyle(Object styleFactory, JComponent component, String regionName)
Called internally by installGtkPopupBugWorkaround.
Class<?> regionClass = Class.forName("javax.swing.plaf.synth.Region");
Field field = regionClass.getField(regionName);
Object region = field.get(regionClass);
Class<?> styleFactoryClass = styleFactory.getClass();
Method method = styleFactoryClass.getMethod("getStyle", new Class<?>[] { JComponent.class, regionClass });
boolean accessible = method.isAccessible();
method.setAccessible(true);
Object style = method.invoke(styleFactory, component, region);
...
ObjectgetGtkStyle(Object styleFactory, JComponent component, String regionName)
Called internally by installGtkPopupBugWorkaround.
Class<?> regionClass = Class.forName("javax.swing.plaf.synth.Region");
Field field = regionClass.getField(regionName);
Object region = field.get(regionClass);
Class<?> styleFactoryClass = styleFactory.getClass();
Method method = styleFactoryClass.getMethod("getStyle", new Class<?>[] { JComponent.class, regionClass });
boolean accessible = method.isAccessible();
method.setAccessible(true);
Object style = method.invoke(styleFactory, component, region);
...
ObjectgetInputHint(JComponent comp)
Returns the component's input hint that is stored in a client property.
return comp.getClientProperty(INPUT_HINT_KEY);
RectanglegetInsetBounds(JComponent comp)
get Inset Bounds
Rectangle bounds = comp.getBounds();
Insets ins = comp.getInsets();
if (ins != null) {
    bounds.x += ins.left;
    bounds.y += ins.top;
    bounds.width -= ins.right + ins.left;
    bounds.height -= ins.top + ins.bottom;
return bounds;
RectanglegetInterior(JComponent comp)
Gets the interior drawing region of a component.
final Insets insets = comp.getInsets();
final Rectangle rect = new Rectangle(0, 0, comp.getWidth(), comp.getHeight());
rect.x += insets.left;
rect.y += insets.top;
rect.width -= insets.left + insets.right;
rect.height -= insets.top + insets.bottom;
return rect;