Java Utililty Methods JTextField Value Get

List of utility methods to do JTextField Value Get

Description

The list of methods to do JTextField Value Get are organized into topic(s).

Method

doublegetDouble(javax.swing.JTextField input)
Get double from the JTextField input
return new Double(input.getText()).doubleValue();
doublegetDoubleFromTextField(JTextField textField, double defaultValue)
get Double From Text Field
double value = defaultValue;
try {
    value = Double.parseDouble(textField.getText());
} catch (NumberFormatException nfe) {
    textField.setText(defaultValue + "");
return value;
doublegetDoubleTextField(javax.swing.JTextField textField)
Return the text field value as a double.
return Double.parseDouble(textField.getText().trim());
StringgetFieldValue(JTextField tf)
get Field Value
String ret = tf.getText().trim();
if (!ret.equals("")) {
    return ret;
return null;
intgetInt(javax.swing.JTextField input)
Get int from the JTextField input
return new Integer(input.getText()).intValue();
intgetInt(JTextField tf)
get Int
return Integer.parseInt(tf.getText());
IntegergetInteger(JTextField txt, Integer defaultVal)
get Integer
String str = txt.getText();
if (str.trim().length() <= 0)
    return defaultVal;
int val = 0;
try {
    val = Integer.parseInt(str);
} catch (NumberFormatException ex) {
return new Integer(val);
intgetIntegerFromTextField(JTextField tf, int previousValue)
Gets the integer from text field.
if (tf.getText().length() > 0) {
    try {
        int num = Integer.parseInt(tf.getText());
        tf.setForeground(Color.black);
        return num;
    } catch (NumberFormatException ex) {
        tf.setForeground(Color.red);
return previousValue;
intgetIntValue(JTextField component)
get Int Value
return Integer.parseInt(component.getText());
StringgetLabelText(JTextField textField)
get Label Text
Container container = textField.getParent();
for (Component component : container.getComponents()) {
    if (component instanceof JLabel) {
        JLabel label = (JLabel) component;
        if (label.getLabelFor() == textField) {
            return label.getText();
return null;