Example usage for javax.swing JTextField setText

List of usage examples for javax.swing JTextField setText

Introduction

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

Prototype

@BeanProperty(bound = false, description = "the text of this component")
public void setText(String t) 

Source Link

Document

Sets the text of this TextComponent to the specified text.

Usage

From source file:com.opendoorlogistics.speedregions.excelshp.app.FileBrowserPanel.java

public static JTextField createTextField(String initialValue, final Consumer<String> filenameChangeListener) {
    final JTextField textField = new JTextField();
    if (initialValue != null) {
        textField.setText(initialValue);
    }//from   w ww.  j  ava2 s  . c o m

    if (filenameChangeListener != null) {
        textField.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void removeUpdate(DocumentEvent e) {
                fire();
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                fire();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                fire();
            }

            private void fire() {
                filenameChangeListener.accept(textField.getText());
            }
        });
    }
    return textField;
}

From source file:max.hubbard.Factoring.Graphing.java

public static void makeGraphingInterface() {

    Interface.mainInterface();/* w w  w.  j a  v  a2s .c  o  m*/

    panel = new JPanel(new BorderLayout(3, 225));

    JPanel pan = new JPanel();
    JLabel area = new JLabel("Graphing");
    area.setBackground(Color.lightGray);
    area.setFont(new Font("Times New Roman", Font.BOLD, 20));
    pan.add(area, BorderLayout.CENTER);

    panel.add(pan, BorderLayout.NORTH);

    final JTextField field = new JTextField();
    panel.add(field, BorderLayout.CENTER);
    field.setFont(new Font("Times New Roman", Font.BOLD, 25));
    field.setText("x^4-2x^2-8");

    JButton start = new JButton("GO!");
    start.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            panel.updateUI();
            Main.label.setText("");
            graph(field.getText());
        }
    });

    panel.add(start, BorderLayout.SOUTH);

    Main.getFrame().add(panel, BorderLayout.EAST);

    Main.getFrame().pack();

}

From source file:com.opendoorlogistics.core.utils.ui.FileBrowserPanel.java

private static JTextField createTextField(String initialFilename,
        final FilenameChangeListener filenameChangeListener) {
    JTextField textField = new JTextField();
    if (initialFilename != null) {
        textField.setText(initialFilename);
    }/*from   ww w  . j  a v  a2  s.  c o  m*/

    if (filenameChangeListener != null) {
        textField.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void removeUpdate(DocumentEvent e) {
                fire();
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                fire();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                fire();
            }

            private void fire() {
                filenameChangeListener.filenameChanged(textField.getText());
            }
        });
    }
    return textField;
}

From source file:br.com.pontocontrol.controleponto.util.SwingUtils.java

public static void validateField(SimpleDateFormat formatter, JTextField field) throws ParseException {
    String valor = field.getText();
    if (StringUtils.isNotBlank(valor)) {
        Date date = formatter.parse(valor);
        field.setText(formatter.format(date));
    }//  ww w . ja  v a 2  s  .co  m
}

From source file:SpringGrid.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//* www  .  j  ava 2 s .c  o m*/
private static void createAndShowGUI() {
    // Create the panel and populate it.
    JPanel panel = new JPanel(new SpringLayout());
    for (int i = 0; i < 9; i++) {
        JTextField textField = new JTextField(Integer.toString(i));

        // Make the 4th field extra big.
        if (i == 4) {
            textField.setText("This one is extra long.");
        }

        panel.add(textField);
    }

    // Lay out the panel.
    SpringUtilities.makeGrid(panel, 3, 3, // rows, cols
            5, 5, // initialX, initialY
            5, 5);// xPad, yPad

    // Create and set up the window.
    JFrame frame = new JFrame("SpringGrid");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Set up the content pane.
    panel.setOpaque(true); // content panes must be opaque
    frame.setContentPane(panel);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
}

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  . j a  va  2  s  . c o  m
            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:ch.admin.hermes.etl.load.HermesETLApplication.java

/**
 * CommandLine parse und fehlende Argumente verlangen
 * @param args Args/*from   w w  w.  j a  va  2  s  .c  o  m*/
 * @throws ParseException
 */
private static void parseCommandLine(String[] args) throws Exception {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    // HACK um UTF-8 CharSet fuer alle Dateien zu setzen (http://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding)
    System.setProperty("file.encoding", "UTF-8");
    Field charset = Charset.class.getDeclaredField("defaultCharset");
    charset.setAccessible(true);
    charset.set(null, null);

    // commandline Options - FremdsystemSite, Username und Password
    Options options = new Options();
    options.addOption("s", true, "Zielsystem - URL");
    options.addOption("u", true, "Zielsystem - Username");
    options.addOption("p", true, "Zielsystem - Password");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);
    site = cmd.getOptionValue("s");
    user = cmd.getOptionValue("u");
    passwd = cmd.getOptionValue("p");

    // restliche Argumente pruefen - sonst usage ausgeben
    String[] others = cmd.getArgs();
    if (others.length >= 1 && (others[0].endsWith(".js") || others[0].endsWith(".ftl")))
        script = others[0];
    if (others.length >= 2 && others[1].endsWith(".xml"))
        model = others[1];

    // Dialog mit allen Werten zusammenstellen
    JComboBox<String> scenarios = new JComboBox<String>(crawler.getScenarios());

    JTextField tsite = new JTextField(45);
    tsite.setText(site);
    JTextField tuser = new JTextField(16);
    tuser.setText(user);
    JPasswordField tpasswd = new JPasswordField(16);
    tpasswd.setText(passwd);
    final JTextField tscript = new JTextField(45);
    tscript.setText(script);
    final JTextField tmodel = new JTextField(45);
    tmodel.setText(model);

    JPanel myPanel = new JPanel(new GridLayout(6, 2));
    myPanel.add(new JLabel("Szenario (von http://www.hermes.admin.ch):"));
    myPanel.add(scenarios);

    myPanel.add(new JLabel("XML Model:"));
    myPanel.add(tmodel);
    JPanel pmodel = new JPanel();
    pmodel.add(tmodel);
    JButton bmodel = new JButton("...");
    pmodel.add(bmodel);
    bmodel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            model = getFile("Szenario XML Model", new String[] { "XML Model" }, new String[] { ".xml" });
            if (model != null)
                tmodel.setText(model);
        }
    });
    myPanel.add(pmodel);

    scenarios.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            try {
                Object o = e.getItem();
                tmodel.setText(crawler.getModelURL(o.toString()));
                scenario = o.toString();
            } catch (Exception e1) {
            }
        }
    });

    // Script
    myPanel.add(new JLabel("Umwandlungs-Script:"));
    JPanel pscript = new JPanel();
    pscript.add(tscript);
    JButton bscript = new JButton("...");
    pscript.add(bscript);
    myPanel.add(pscript);
    bscript.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            script = getFile("JavaScript/Freemarker Umwandlungs-Script",
                    new String[] { "JavaScript", "Freemarker" }, new String[] { ".js", ".ftl" });
            if (script != null)
                tscript.setText(script);
        }
    });

    // Zielsystem Angaben
    myPanel.add(new JLabel("Zielsystem URL:"));
    myPanel.add(tsite);
    myPanel.add(new JLabel("Zielsystem Benutzer:"));
    myPanel.add(tuser);
    myPanel.add(new JLabel("Zielsystem Password:"));
    myPanel.add(tpasswd);

    // Trick um Feld scenario und model zu setzen.
    if (scenarios.getItemCount() >= 8)
        scenarios.setSelectedIndex(8);

    // Dialog
    int result = JOptionPane.showConfirmDialog(null, myPanel, "HERMES 5 XML Model nach Fremdsystem/Format",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.OK_OPTION) {
        site = tsite.getText();
        user = tuser.getText();
        passwd = new String(tpasswd.getPassword());
        model = tmodel.getText();
        script = tscript.getText();
    } else
        System.exit(1);

    if (model == null || script == null || script.trim().length() == 0)
        usage();

    if (script.endsWith(".js"))
        if (site == null || user == null || passwd == null || user.trim().length() == 0
                || passwd.trim().length() == 0)
            usage();
}

From source file:br.com.pontocontrol.controleponto.util.SwingUtils.java

public static void validateTimeFields(JTextField... fields) {
    for (JTextField field : fields) {
        Calendar dataSaida = null;
        try {//ww w .  jav a2s  .c o  m
            dataSaida = getCalendarValueFromField(SIMPLE_TIME_FORMATTER_A, field);
        } catch (ParseException ex) {
            try {
                dataSaida = getCalendarValueFromField(SIMPLE_TIME_FORMATTER_B, field);
            } catch (ParseException ex1) {
                try {
                    dataSaida = getCalendarValueFromField(SIMPLE_TIME_FORMATTER_C, field);
                } catch (ParseException ex2) {
                }
            }
        }
        if (dataSaida != null) {
            String valTxt = SIMPLE_TIME_FORMATTER_A.format(dataSaida.getTime());
            field.setText(valTxt);
        } else {
            field.setText("");
        }
    }
}

From source file:de.dakror.virtualhub.server.dialog.BackupEditDialog.java

public static void show() throws JSONException {
    final JDialog dialog = new JDialog(Server.currentServer.frame, "Backup-Einstellungen", true);
    dialog.setSize(400, 250);// w w  w . j  ava 2 s  .c om
    dialog.setLocationRelativeTo(Server.currentServer.frame);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    JPanel cp = new JPanel(new SpringLayout());
    cp.add(new JLabel("Zielverzeichnis:"));
    JPanel panel = new JPanel();
    final JTextField path = new JTextField((Server.currentServer.settings.has("backup.path")
            ? Server.currentServer.settings.getString("backup.path")
            : ""), 10);
    panel.add(path);
    panel.add(new JButton(new AbstractAction("Whlen...") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser jfc = new JFileChooser((path.getText().length() > 0 ? new File(path.getText())
                    : new File(System.getProperty("user.home"))));
            jfc.setFileHidingEnabled(false);
            jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            jfc.setDialogTitle("Backup-Zielverzeichnis whlen");

            if (jfc.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION)
                path.setText(jfc.getSelectedFile().getPath().replace("\\", "/"));
        }
    }));

    cp.add(panel);

    cp.add(new JLabel(""));
    cp.add(new JLabel(""));

    cp.add(new JButton(new AbstractAction("Abbrechen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    }));
    cp.add(new JButton(new AbstractAction("Speichern") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                if (path.getText().length() > 0)
                    Server.currentServer.settings.put("backup.path", path.getText());
                dialog.dispose();
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        }
    }));

    SpringUtilities.makeCompactGrid(cp, 3, 2, 6, 6, 6, 6);
    dialog.setContentPane(cp);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:EvenOddRowCellRenderer.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    JTextField editor = new JTextField();
    if (value != null)
        editor.setText(value.toString());
    editor.setBackground((row % 2 == 0) ? Color.white : Color.cyan);
    return editor;
}