Java Utililty Methods JPanel Child

List of utility methods to do JPanel Child

Description

The list of methods to do JPanel Child are organized into topic(s).

Method

voidaddTwoCheckBoxes(JPanel panel, JCheckBox first, boolean firstChecked, JCheckBox second, boolean secondChecked)
add Two Check Boxes
first.setSelected(firstChecked);
panel.add(first);
if (second != null) {
    second.setSelected(secondChecked);
    panel.add(second);
voidaddUIComponent(JPanel jp, JComponent jc, int loc, int type, int[] decart, Insets insets)
add UI Component
GridBagConstraints c = new GridBagConstraints();
c.anchor = loc;
c.fill = type;
c.gridx = decart[0];
c.gridy = decart[1];
c.gridwidth = decart[2];
c.gridheight = decart[3];
c.weightx = (double) (((4 - type) & 2) >> 1);
...
voidaddWidth(JPanel panel, int width)
add Width
panel.add(Box.createRigidArea(new Dimension(width, 0)));
voidaddWithPadding(JPanel parentPanel, JPanel panelToBeAdded)
add With Padding
JPanel spaceContainer = new JPanel();
spaceContainer.setBorder(new EmptyBorder(3, 3, 3, 3));
spaceContainer.add(panelToBeAdded);
parentPanel.add(spaceContainer);
voidfillPanel(final JPanel panel, final GridBagConstraints gbc)
fill Panel
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridwidth = 2;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
panel.add(new JPanel(), gbc);
JPanelfillPanel(JPanel panel, Component... components)
fill Panel
for (Component component : components) {
    panel.add(component);
return panel;
WindowConstantsgetOutermostContainer(JPanel container)
get Outermost Container
Container pnl = container;
while (pnl.getParent() != null) {
    if (pnl.getParent() instanceof JInternalFrame) {
        return (JInternalFrame) pnl.getParent();
    if (pnl.getParent() instanceof JDialog) {
        return (JDialog) pnl.getParent();
    if (pnl.getParent() instanceof JFrame) {
        return (JFrame) pnl.getParent();
    pnl = pnl.getParent();
return null;
voidpackPanel(JPanel p, int width)
pack Panel
int minh = 0;
for (Component c : p.getComponents()) {
    minh += c.getMinimumSize().getHeight();
p.setMinimumSize(new Dimension(width, minh));
p.setMaximumSize(new Dimension(width, minh));
voidpadPanel(Object innerPanel, JPanel outerPanel, int pad)
pad Panel
final GridBagConstraints c;
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.NORTHWEST;
c.insets = new Insets(pad, pad, pad, pad);
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
...
voidremoveComponentFromPanel(Component removeComponent, JPanel fromPanel)
removePanelFromPanel removes a specific Component from another panel
fromPanel.remove(removeComponent);
fromPanel.revalidate();
fromPanel.repaint();