List of usage examples for javax.swing JTextField getText
public String getText()
TextComponent
. 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 ww. j a va 2 s. c o m*/ 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:com.opendoorlogistics.core.utils.ui.FileBrowserPanel.java
private static JButton createBrowseButton(final boolean directoriesOnly, final String browserApproveButtonText, final JTextField textField, final FileFilter... fileFilters) { JButton browseButton = new JButton("..."); browseButton.addActionListener(new ActionListener() { @Override/* w w w . j a va 2 s . co m*/ public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); if (textField.getText() != null) { File file = new File(textField.getText()); // if the file doesn't exist but the directory does, get that if (!file.exists() && file.getParentFile() != null && file.getParentFile().exists()) { file = file.getParentFile(); } if (!directoriesOnly && file.isFile()) { chooser.setSelectedFile(file); } if (file.isDirectory() && file.exists()) { chooser.setCurrentDirectory(file); } } if (directoriesOnly) { chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } // add filters and automatically select correct one if (fileFilters.length == 1) { chooser.setFileFilter(fileFilters[0]); } else { for (FileFilter filter : fileFilters) { chooser.addChoosableFileFilter(filter); if (filter instanceof FileNameExtensionFilter) { if (matchesFilter((FileNameExtensionFilter) filter, textField.getText())) { chooser.setFileFilter(filter); } } } } if (chooser.showDialog(textField, browserApproveButtonText) == JFileChooser.APPROVE_OPTION) { //File selected = processSelectedFile(chooser.getSelectedFile()); File selected = chooser.getSelectedFile(); String path = selected.getPath(); FileFilter filter = chooser.getFileFilter(); if (filter != null && filter instanceof FileNameExtensionFilter) { boolean found = matchesFilter(((FileNameExtensionFilter) chooser.getFileFilter()), path); if (!found) { String[] exts = ((FileNameExtensionFilter) chooser.getFileFilter()).getExtensions(); if (exts.length > 0) { path = FilenameUtils.removeExtension(path); path += "." + exts[0]; } } } textField.setText(path); } } }); return browseButton; }
From source file:max.hubbard.Factoring.Graphing.java
public static void makeGraphingInterface() { Interface.mainInterface();//from w w w .j av a2s .c om 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:edu.ku.brc.specify.config.init.RegisterSpecify.java
/** * Registers the ISA number.// w w w. ja v a 2 s . c om */ public static void registerISA() { SpecifyUser spUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class); if (!spUser.getUserType().equals(SpecifyUserTypes.UserType.Manager.toString())) { UIRegistry.showLocalizedMsg("", "SpReg.MUSTBECM"); return; } Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class); String isaNumber = collection.getIsaNumber(); String isaTitle = getResourceString("SpReg.ISA_TITLE"); if (StringUtils.isNotEmpty(isaNumber)) { String msg = UIRegistry.getLocalizedMessage("SpReg.ISA_NUM", isaNumber); JOptionPane.showMessageDialog(UIRegistry.getTopWindow(), msg, isaTitle, JOptionPane.INFORMATION_MESSAGE); } else { final JTextField textField = UIHelper.createTextField(30); isaNumber = textField.getText(); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,10px,p")); pb.add(UIHelper.createI18NFormLabel("SpReg.ISA_ENT"), cc.xy(1, 1)); pb.add(textField, cc.xy(3, 1)); pb.add(UIHelper.createI18NLabel("SpReg.ISA_EXPL"), cc.xyw(1, 3, 3)); pb.setDefaultDialogBorder(); CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(), isaTitle, true, pb.getPanel()); dlg.createUI(); final JButton okBtn = dlg.getOkBtn(); okBtn.setEnabled(false); textField.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { if (StringUtils.isNotEmpty(textField.getText()) != okBtn.isEnabled()) { okBtn.setEnabled(!okBtn.isEnabled()); } } }); dlg.setVisible(true); isaNumber = textField.getText(); if (!dlg.isCancelled() && StringUtils.isNotEmpty(isaNumber)) { setIsAnonymous(false); collection.setIsaNumber(isaNumber); getInstance().doStartRegister(RegisterType.Collection, false, true); AppPreferences.getLocalPrefs().putBoolean(EXTRA_CHECK, true); } } }
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); }// w ww. jav a 2s. co 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:Main.java
public boolean verify(JComponent input) { JTextField tf = (JTextField) input; String pass = tf.getText(); return pass.equals("AA"); }
From source file:Main.java
public boolean verify(JComponent input) { JTextField tf = (JTextField) input; String pass = tf.getText(); return pass.equals("A"); }
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 w w w . j ava 2 s. c om 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:Main.java
public Main() throws HeadlessException { setSize(200, 200);/*w w w . java2 s .c o m*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel usernameLabel = new JLabel("Username: "); JTextField usernameTextField = new JTextField(); usernameTextField.setPreferredSize(new Dimension(100, 20)); add(usernameLabel); add(usernameTextField); usernameTextField.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { JTextField textField = (JTextField) e.getSource(); String text = textField.getText(); textField.setText(text.toUpperCase()); } public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { } }); }
From source file:com.bsb.intellij.plugins.xmlbeans.facet.ui.validation.ValidJvmMemoryParameterValidator.java
@Nullable @Override/* w w w. j a v a 2 s .co m*/ public String getErrorMessage(JTextField textField, JBLabel label) { String text = textField.getText(); if (StringUtils.isNotBlank(text) && !ValidationUtils.isValidJvmMemoryParameter(text)) { return label.getText() + " should be a valid memory parameter (e.g. 256M)"; } return null; }