Java JButton normalizeComponentDimension(JComponent[] jButtonList)

Here you can find the source of normalizeComponentDimension(JComponent[] jButtonList)

Description

Normalization of the size for all JComponent.

License

Open Source License

Parameter

Parameter Description
jButtonList a parameter

Declaration

public static void normalizeComponentDimension(JComponent[] jButtonList) 

Method Source Code

//package com.java2s;
/*************************************************************************
    /* w w  w .ja v  a 2 s  . c  om*/
Copyright (C) 2009 Grandite
    
This file is part of Open ModelSphere.
    
Open ModelSphere 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 3 of the License, or
(at your option) any later version.
    
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
or see http://www.gnu.org/licenses/.
    
You can redistribute and/or modify this particular file even under the
terms of the GNU Lesser General Public License (LGPL) as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
    
You should have received a copy of the GNU Lesser General Public License 
(LGPL) along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
or see http://www.gnu.org/licenses/.
    
You can reach Grandite at: 
    
20-1220 Lebourgneuf Blvd.
Quebec, QC
Canada  G2K 2G4
    
or
    
open-modelsphere@grandite.com
    
 **********************************************************************/

import java.awt.*;

import javax.swing.*;

public class Main {
    /**
     * Normalization of the size for all JComponent.
     * 
     * @param jButtonList
     */
    public static void normalizeComponentDimension(JComponent[] jButtonList) {
        normalizeComponentDimension(jButtonList, null);
    }

    /**
     * 
     * Normalization of the size for all JComponent.
     * 
     * @param jButtonList
     * @param jPossibleButtonList
     */
    public static void normalizeComponentDimension(JComponent[] jButtonList, JComponent[] jPossibleButtonList) {
        int i;
        int buttonWidth = 0;
        int buttonHeigth = 0;

        // We must set the preferred size to Null if we want change it more than
        // once
        for (i = 0; i < jButtonList.length; i++) {
            jButtonList[i].setPreferredSize(null);
        }

        // Calculating the maximum preferred size
        if (jPossibleButtonList == null) {
            jPossibleButtonList = jButtonList;
        }
        for (i = 0; i < jPossibleButtonList.length; i++) {
            buttonWidth = Math.max(buttonWidth, jPossibleButtonList[i].getPreferredSize().width);
            buttonHeigth = Math.max(buttonHeigth, jPossibleButtonList[i].getPreferredSize().height);
        }

        // Affectation of the same preferred size for all buttons
        buttonWidth = Math.min(buttonWidth, 100); // limit the width of small
        // buttons to 100 if there
        // are buttons larger than
        // 100
        for (i = 0; i < jButtonList.length; i++) {
            int width = Math.max(buttonWidth, jButtonList[i].getPreferredSize().width);
            Dimension size = new Dimension(width, buttonHeigth);
            jButtonList[i].setPreferredSize(size);
            jButtonList[i].setMinimumSize(size);
        }
    }
}

Related

  1. getButtonNumber(JButton btn)
  2. getScrollStroke(final JButton _jlbl_stroke)
  3. getWFStep(Vector actionButtons, String action)
  4. initHelpButton(final JButton buttonHelp)
  5. nombreImg(JButton boton)
  6. nullifyButtonUI(final JButton button)
  7. orderOKCancelButtons(JButton okButton, JButton cancelButton)
  8. reduceNimbusButtonMargin(final JButton button)
  9. registerCancelButton(final JButton cancelButton)