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

voidallignBottom(JComponent lead, JComponent target)
allign Bottom
allignBottom(lead, target, -1, -1);
voidcenterComponent(final JComponent target)
Centers JComponent on screen
final Rectangle screen = getScreenRect();
final Rectangle frameSize = target.getBounds();
final int x = (screen.width - frameSize.width) / 2;
final int y = (screen.height - frameSize.height) / 2;
target.setLocation(x, y);
voidcenterOnComponet(Window target, JComponent parent)
center On Componet
Dimension targetSize = target.getSize();
Point location = parent.getLocationOnScreen();
Dimension sourceSize = parent.getSize();
Point sourceCenter = new Point(location.x + sourceSize.width / 2, location.y + sourceSize.height / 2);
Point frameLocation = new Point(sourceCenter.x - targetSize.width / 2,
        sourceCenter.y - targetSize.height / 2);
target.setLocation(frameLocation);
RectanglecheckComponents(final Component _rootComponent, final String _print, final int _currentColumn, final int _currentRow)
Check the components.
int depth = _currentColumn;
int amount = _currentRow;
int maxDepth = _currentColumn;
if (_rootComponent.getWidth() <= 0 || _rootComponent.getHeight() <= 0) {
    System.err.println(_print + _rootComponent.getClass().getSimpleName() + _rootComponent.getSize());
} else {
    System.out.println(_print + _rootComponent.getClass().getSimpleName()
    );
...
JRootPanefindMainRootPane(Component component)
find Main Root Pane
while (component != null) {
    Container parent = component.getParent();
    if (parent == null) {
        return component instanceof RootPaneContainer ? ((RootPaneContainer) component).getRootPane()
                : null;
    component = parent;
return null;
JRootPanefindRootPane(Component component)
find Root Pane
while (component != null) {
    if (component instanceof JRootPane) {
        return (JRootPane) component;
    component = getParent(component);
return null;
RootPaneContainerfindRootPaneContainer(Component c)
Locates the RootPaneContainer for the given component
if (c == null) {
    return null;
} else if (c instanceof RootPaneContainer) {
    return (RootPaneContainer) c;
} else {
    return findRootPaneContainer(c.getParent());
RootPaneContainerfindRootPaneContainer(Component root)
Finds the nearest RootPaneContainer of the provided Component.
while (root != null) {
    if (root instanceof RootPaneContainer) {
        return (RootPaneContainer) root;
    } else if (root instanceof JPopupMenu && root.getParent() == null) {
        root = ((JPopupMenu) root).getInvoker();
    } else {
        root = root.getParent();
return null;
RootPaneContainerfindRootPaneContainer(final Component source)
Find the root pane container in the current hierarchy.
Component comp = source;
while ((comp != null) && !(comp instanceof RootPaneContainer)) {
    comp = comp.getParent();
if (comp instanceof RootPaneContainer) {
    return (RootPaneContainer) comp;
return null;
...
RectanglegetActiveRectangle(JComponent c)
get Active Rectangle
Dimension d = c.getSize();
Insets ins = c.getInsets();
int left = ins.left;
int width = d.width - ins.right - ins.left;
int top = ins.top;
int height = d.height - ins.bottom - ins.top;
Rectangle ret = new Rectangle(left, top, width, height);
return ret;
...