Java JTextField Value Get getLabelText(JTextField textField)

Here you can find the source of getLabelText(JTextField textField)

Description

get Label Text

License

Open Source License

Declaration

public static String getLabelText(JTextField textField) 

Method Source Code


//package com.java2s;
/*/*from  ww w  . j a  v a2s .c o m*/
* Argus Open Source
* Software to apply Statistical Disclosure Control techniques
* 
* Copyright 2014 Statistics Netherlands
* 
* This program is free software; you can redistribute it and/or 
* modify it under the terms of the European Union Public Licence 
* (EUPL) version 1.1, as published by the European Commission.
* 
* You can find the text of the EUPL v1.1 on
* https://joinup.ec.europa.eu/software/page/eupl/licence-eupl
* 
* This software is distributed on an "AS IS" basis without 
* warranties or conditions of any kind, either express or implied.
*/

import java.awt.Component;
import java.awt.Container;

import javax.swing.JLabel;

import javax.swing.JTextField;

public class Main {
    public static String getLabelText(JTextField textField) {
        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;
    }
}

Related

  1. getInt(javax.swing.JTextField input)
  2. getInt(JTextField tf)
  3. getInteger(JTextField txt, Integer defaultVal)
  4. getIntegerFromTextField(JTextField tf, int previousValue)
  5. getIntValue(JTextField component)
  6. getText(JTextField text)
  7. hasValue(JTextField... fields)
  8. largeThan(javax.swing.JTextField input, int x, Vector errMsgList, String errMsg)