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

RectanglegetLocalInsetBounds(JComponent component)
get Local Inset Bounds
Insets insets = component.getInsets();
return new Rectangle(insets.left, insets.top, component.getWidth() - (insets.left + insets.right),
        component.getHeight() - (insets.top + insets.bottom));
ComponentgetMandatoryPanel(JComponent c)
get Mandatory Panel
Box box = Box.createHorizontalBox();
box.add(c);
box.add(new JLabel(LABEL_MANDATORY));
return box;
intgetMaxVisibleY(JComponent comp)
get Max Visible Y
final Rectangle rect = comp.getVisibleRect();
return rect.y + rect.height - 1;
ObjectgetModelObject(JComponent c)
get Model Object
if (c instanceof JTree) {
    final TreePath path = ((JTree) c).getSelectionPath();
    final Object pathComponent = path.getLastPathComponent();
    if (pathComponent instanceof DefaultMutableTreeNode) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathComponent;
        final Object userObject = node.getUserObject();
        return userObject;
return null;
JRootPanegetOutermostRootPane(Component c)
If c is a JRootPane descendant return its outermost JRootPane ancestor.
if (c instanceof RootPaneContainer && c.getParent() == null) {
    return ((RootPaneContainer) c).getRootPane();
JRootPane lastRootPane;
for (; c != null; c = SwingUtilities.getRootPane(c)) {
    if (c instanceof JRootPane) {
        lastRootPane = (JRootPane) c;
        if (c.getParent().getParent() == null) {
...
JRootPanegetOutermostRootPane(Component c)
get Outermost Root Pane
if (((c instanceof RootPaneContainer)) && (c.getParent() == null)) {
    return ((RootPaneContainer) c).getRootPane();
for (; c != null; c = SwingUtilities.getRootPane(c)) {
    if ((c instanceof JRootPane)) {
        JRootPane lastRootPane = (JRootPane) c;
        if (c.getParent().getParent() == null) {
            return lastRootPane;
...
JPanelgetPanelFor(JComponent comp1, JComponent comp2)
get Panel For
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.CENTER));
panel.add(comp1);
panel.add(comp2);
return panel;
JPanelgetPanelFor(JComponent comp1, JComponent comp2)
get Panel For
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.LEFT));
panel.add(comp1);
panel.add(comp2);
return panel;
JComponentgetParent(JComponent parent, final int... path)
get Parent
for (final int i : path) {
    parent = (JComponent) parent.getComponent(i);
return parent;
ContainergetParentPanel(JComponent jc)
go to parent that is not a scroll pane
Container parent = jc.getParent();
while (parent != null) {
    if (parent instanceof JPanel)
        return parent;
    if (parent instanceof JFrame)
        return parent;
    if (parent instanceof JDialog)
        return parent;
...