Java JButton buttonState(JButton button, boolean boolArrayOfErrors[])

Here you can find the source of buttonState(JButton button, boolean boolArrayOfErrors[])

Description

Takes a JButton and a boolean array of errors.

License

Open Source License

Parameter

Parameter Description
button a parameter
boolArrayOfErrors a parameter

Declaration

public static void buttonState(JButton button, boolean boolArrayOfErrors[]) 

Method Source Code

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

import javax.swing.JButton;

public class Main {
    /**//ww w .  j  ava2 s  . co m
     * Takes a JButton and a boolean array of errors.
     * 
     * It checks to see if errors are present, if not it enables the button If
     * true it disables the button.
     * 
     * 
     * @param button
     * @param boolArrayOfErrors
     */
    public static void buttonState(JButton button, boolean boolArrayOfErrors[]) {
        if (!isErrorPresent(boolArrayOfErrors)) {
            button.setEnabled(true);
        } else {
            button.setEnabled(false);
        }
    }

    /**
     * Takes an array of booleans, if one true is found then this returns true
     * indicating that an error is present.
     * 
     * Else it returns false meaning no errors are present.
     * 
     * 
     * @param values
     * @return true/false
     */
    public static boolean isErrorPresent(boolean[] values) {
        for (boolean value : values) {
            if (value)
                return true;
        }
        return false;
    }
}

Related

  1. addCRListener(JComponent c, final JButton b)
  2. addEnterListener(JComponent c, final JButton b)
  3. adjustButtonMargins(Insets margin, JButton... buttons)
  4. adjustButtonWidth(JButton button, int minWidth, int minHeight)
  5. btnHover(JButton btn)
  6. closeFrame(JButton thisButton)
  7. configureButton(JButton button)
  8. considerarSetaComoTab(JButton comp)
  9. copyButtonWidth(JButton toButton, JButton fromButton)