Java JTextField addLabelTextRows(JLabel[] labels, JTextField[] textFields, GridBagLayout gridbag, Container container)

Here you can find the source of addLabelTextRows(JLabel[] labels, JTextField[] textFields, GridBagLayout gridbag, Container container)

Description

add Label Text Rows

License

Open Source License

Declaration

public static void addLabelTextRows(JLabel[] labels, JTextField[] textFields, GridBagLayout gridbag,
            Container container) 

Method Source Code


//package com.java2s;
/*//from w  w w .  j  a  va 2 s .  c  o  m
  Copyright (c) 2006 Harri Kaimio
      
  This file is part of Photovault.
    
  Photovault is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
    
  Photovault is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.
    
  You should have received a copy of the GNU General Public License
  along with Photovault; if not, write to the Free Software Foundation,
  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

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

public class Main {
    public static void addLabelTextRows(JLabel[] labels, JTextField[] textFields, GridBagLayout gridbag,
            Container container) {
        GridBagConstraints c = new GridBagConstraints();
        c.anchor = GridBagConstraints.EAST;
        c.insets = new Insets(2, 2, 2, 2);
        int numLabels = labels.length;

        for (int i = 0; i < numLabels; i++) {
            c.anchor = GridBagConstraints.EAST;
            c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
            c.fill = GridBagConstraints.NONE; //reset to default
            c.weightx = 0.0; //reset to default
            gridbag.setConstraints(labels[i], c);
            container.add(labels[i]);

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER; //end row
            c.weightx = 1.0;
            gridbag.setConstraints(textFields[i], c);
            container.add(textFields[i]);
        }
    }
}

Related

  1. addHighlight(JTextField label, MouseEvent mouseEvent1, MouseEvent mouseEvent2)
  2. addInputValidator(final DocumentListener inputValidator, final JTextField... textFields)
  3. addPlaceHolder(final JTextField field, final String placeHolderText)
  4. addStyle(JTextField textField, String labelName)
  5. adjustTextToRight(JTextField textField)
  6. applyDefaultProperties(final JTextField comp)