Example usage for javax.swing JTextField getText

List of usage examples for javax.swing JTextField getText

Introduction

In this page you can find the example usage for javax.swing JTextField getText.

Prototype

public String getText() 

Source Link

Document

Returns the text contained in this TextComponent.

Usage

From source file:com.SCI.centraltoko.utility.UtilityTools.java

private static void convertToUpperCase(final JTextField textField) {
    textField.setText(textField.getText().toUpperCase());
}

From source file:com.SCI.centraltoko.utility.UtilityTools.java

private static void batasInput(JTextField textFIle, KeyEvent keyEven, int maxIsi) {
    if (textFIle.getText().length() + 1 > maxIsi) {
        keyEven.consume();//w ww .  j  a v a2  s.  c  o  m
    }
}

From source file:com.SCI.centraltoko.utility.UtilityTools.java

public static String getValueFromTextNumber(final JTextField textField) {
    final char[] txt = textField.getText().toCharArray();
    StringBuilder sb = new StringBuilder();
    @SuppressWarnings("UnusedAssignment")
    String tmp = "";
    for (int i = 0; i < txt.length; i++) {
        tmp = String.valueOf(txt[i]);
        if (tmp.equals(".") || tmp.equals(",")) {

        } else {//from  w ww .  j a va 2 s.c om
            sb.append(tmp);
        }
    }
    return sb.toString();
}

From source file:city_planning.initialize_fields.Initialize_search_record_field_types.java

public static void init_regions(final JTextField tf) {

    Object[][] obj = null;/* ww w.  ja v a 2s.c  o  m*/
    int i = 0;
    if (tf.getText().isEmpty()) {
        obj = new Object[regions.size()][1];
        for (Regions.to_regions to : regions) {
            obj[i][0] = " " + to.region;
            i++;
        }
    } else {
        List<Regions.to_regions> in_search = new ArrayList();
        for (Regions.to_regions to : regions) {
            boolean contains = StringUtils.containsIgnoreCase(to.region, tf.getText());
            if (contains) {
                in_search.add(to);
            }
        }
        obj = new Object[in_search.size()][1];
        for (Regions.to_regions to : in_search) {
            obj[i][0] = " " + to.region;
            i++;
        }
    }

    JLabel[] labels = {};
    int[] tbl_widths_customers = { tf.getWidth() };
    String[] col_names = { "Name" };
    TableRenderer tr = new TableRenderer();
    TableRenderer.setPopup(tf, obj, labels, tbl_widths_customers, col_names);
    tr.setCallback(new TableRenderer.Callback() {
        @Override
        public void ok(TableRenderer.OutputData data) {
            Regions.to_regions to = regions.get(data.selected_row);
            Field.Combo field = (Field.Combo) tf;
            field.setText(to.region);
            field.setId("" + to.id);
        }
    });
}

From source file:city_planning.initialize_fields.Initialize_search_record_field_types.java

public static void init_cities(final JTextField tf) {

    Object[][] obj = null;//w  w  w  . j a v  a 2 s . com
    int i = 0;
    if (tf.getText().isEmpty()) {
        obj = new Object[cities.size()][1];
        for (Cities.to_cities to : cities) {
            obj[i][0] = " " + to.city;
            i++;
        }
    } else {
        List<Cities.to_cities> in_search = new ArrayList();
        for (Cities.to_cities to : cities) {
            boolean contains = StringUtils.containsIgnoreCase(to.city, tf.getText());
            if (contains) {
                in_search.add(to);
            }
        }
        obj = new Object[in_search.size()][1];
        for (Cities.to_cities to : in_search) {
            obj[i][0] = " " + to.city;
            i++;
        }
    }

    JLabel[] labels = {};
    int[] tbl_widths_customers = { tf.getWidth() };
    String[] col_names = { "Name" };
    TableRenderer tr = new TableRenderer();
    TableRenderer.setPopup(tf, obj, labels, tbl_widths_customers, col_names);
    tr.setCallback(new TableRenderer.Callback() {
        @Override
        public void ok(TableRenderer.OutputData data) {
            Cities.to_cities to = cities.get(data.selected_row);
            Field.Combo field = (Field.Combo) tf;
            field.setText(to.city);
            field.setId("" + to.id);

        }
    });
}

From source file:city_planning.initialize_fields.Initialize_search_record_field_types.java

public static void init_provinces(final JTextField tf, final JTextField tf_regions) {

    Object[][] obj = null;/*www . j  a  v  a  2 s . c  o  m*/
    int i = 0;
    if (tf.getText().isEmpty()) {
        obj = new Object[provinces.size()][1];
        for (Provinces.to_provinces to : provinces) {
            obj[i][0] = " " + to.province;
            i++;
        }
    } else {
        List<Provinces.to_provinces> in_search = new ArrayList();
        for (Provinces.to_provinces to : provinces) {
            boolean contains = StringUtils.containsIgnoreCase(to.province, tf.getText());
            if (contains) {
                in_search.add(to);
            }
        }
        obj = new Object[in_search.size()][1];
        for (Provinces.to_provinces to : in_search) {
            obj[i][0] = " " + to.province;
            i++;
        }
    }

    JLabel[] labels = {};
    int[] tbl_widths_customers = { tf.getWidth() };
    String[] col_names = { "Name" };
    TableRenderer tr = new TableRenderer();
    TableRenderer.setPopup(tf, obj, labels, tbl_widths_customers, col_names);
    tr.setCallback(new TableRenderer.Callback() {
        @Override
        public void ok(TableRenderer.OutputData data) {
            Provinces.to_provinces to = provinces.get(data.selected_row);
            Field.Combo field = (Field.Combo) tf;
            Field.Combo field_region = (Field.Combo) tf_regions;
            field.setText(to.province);
            field.setId("" + to.id);

            field_region.setText(to.region);
            field_region.setId(to.region_id);

        }
    });
}

From source file:Main.java

public static void addPlaceHolder(final JTextField field, final String placeHolderText) {
    field.addFocusListener(new FocusListener() {
        private Color fontColor = field.getForeground();

        //          private String previousText=field.getText();

        public void focusGained(FocusEvent arg0) {
            if (field.getText().equals(placeHolderText)) {
                field.setText("");
            }/*w  w w  .  java 2  s  .c  om*/
            field.setForeground(fontColor);
        }

        public void focusLost(FocusEvent arg0) {
            if (field.getText().trim().equals("")) {
                fontColor = field.getForeground();
                field.setForeground(Color.GRAY);
                field.setText(placeHolderText);
            }
        }
    });
    if (field.getText().trim().equals("")) {
        field.setText(placeHolderText);
        field.setForeground(Color.GRAY);
    }
}

From source file:com.sciaps.utils.Util.java

public static int validateZeroOrGreater(JTextField txtField) {

    Pattern pattern = Pattern.compile(POSITIVE_INT);
    if (pattern.matcher(txtField.getText()).matches()) {
        txtField.setBackground(Color.white);
        return getStringToInt(txtField.getText());
    }/*from  w  w  w . j  av a  2s  .c  om*/

    txtField.setBackground(Color.red);
    return -1;
}

From source file:com.sciaps.utils.Util.java

public static int validateOneOrGreater(JTextField txtField) {

    Pattern pattern = Pattern.compile(POSITIVE_INT);
    if (pattern.matcher(txtField.getText()).matches()) {
        int val = getStringToInt(txtField.getText());
        if (val > 0) {
            txtField.setBackground(Color.white);
            return val;
        }/*from ww w  . j  a v  a2s. c  o m*/
    }

    txtField.setBackground(Color.red);
    return -1;
}

From source file:net.minder.KnoxWebHdfsJavaClientExamplesTest.java

@BeforeClass
public static void setupSuite() {
    Console console = System.console();
    if (console != null) {
        console.printf("Knox Host: ");
        KNOX_HOST = console.readLine();/* w  w w . ja  va2  s  .  co m*/
        console.printf("Topology : ");
        TOPOLOGY_PATH = console.readLine();
        console.printf("Username : ");
        TEST_USERNAME = console.readLine();
        console.printf("Password: ");
        TEST_PASSWORD = new String(console.readPassword());
    } else {
        JLabel label = new JLabel("Enter Knox host, topology, username, password:");
        JTextField host = new JTextField(KNOX_HOST);
        JTextField topology = new JTextField(TOPOLOGY_PATH);
        JTextField username = new JTextField(TEST_USERNAME);
        JPasswordField password = new JPasswordField(TEST_PASSWORD);
        int choice = JOptionPane.showConfirmDialog(null,
                new Object[] { label, host, topology, username, password }, "Credentials",
                JOptionPane.OK_CANCEL_OPTION);
        assertThat(choice, is(JOptionPane.YES_OPTION));
        TEST_USERNAME = username.getText();
        TEST_PASSWORD = new String(password.getPassword());
        KNOX_HOST = host.getText();
        TOPOLOGY_PATH = topology.getText();
    }
    TOPOLOGY_URL = String.format("%s://%s:%d/%s/%s", KNOX_SCHEME, KNOX_HOST, KNOX_PORT, KNOX_PATH,
            TOPOLOGY_PATH);
    WEBHDFS_URL = String.format("%s/%s", TOPOLOGY_URL, WEBHDFS_PATH);
}