Java JLabel addParameterRow(Container container, JLabel label, Component component)

Here you can find the source of addParameterRow(Container container, JLabel label, Component component)

Description

Add a label-value pair to a container that uses GridBagLayout.

License

Open Source License

Declaration

public static void addParameterRow(Container container, JLabel label, Component component) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.*;
import javax.swing.*;

public class Main {
    /**/*from  w  ww .  j a  v  a  2 s .  co m*/
     * Add a label-value pair to a container that uses
     * GridBagLayout.
     */
    public static void addParameterRow(Container container, JLabel label, Component component) {
        GridBagLayout gridbag = null;
        try {
            gridbag = (GridBagLayout) (container.getLayout());
        } catch (Exception e) {
            System.err
                    .println("Hey!  You called addRow with" + " a container that doesn't " + " use GridBagLayout!");
            return;
        }

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;
        //c.weighty = 1.0;
        c.insets = new Insets(0, 5, 0, 5);

        gridbag.setConstraints(label, c);
        container.add(label);
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.weightx = 1.0;
        gridbag.setConstraints(component, c);
        container.add(component);
    }
}

Related

  1. addMessageLogger(JLabel t)
  2. clear(JLabel... fields)
  3. ensureCustomBackgroundStored(JLabel comp)
  4. exibeMensagemTemporaria(final JLabel lblMensagem, String mensagem)
  5. extendByIcon(JLabel label, Dimension dm)