List of usage examples for javax.swing JTextField setText
@BeanProperty(bound = false, description = "the text of this component") public void setText(String t)
TextComponent
to the specified text. From source file:Main.java
public Main() throws HeadlessException { setSize(200, 200);//from ww w. j a v a 2 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:Main.java
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { JTextField editor = (JTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column); if (value != null) editor.setText(value.toString()); if (column == 0) { editor.setHorizontalAlignment(SwingConstants.CENTER); editor.setFont(new Font("Serif", Font.BOLD, 14)); } else {/*from w ww . jav a 2 s . c o m*/ editor.setHorizontalAlignment(SwingConstants.RIGHT); editor.setFont(new Font("Serif", Font.ITALIC, 12)); } return editor; }
From source file:biomine.bmvis2.pipeline.EdgeGoodnessHider.java
public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { double maxEdge = 0; for (VisualEdge e : graph.getAllEdges()) { maxEdge = Math.max(maxEdge, e.getGoodness()); }/* w w w. j av a 2s .c o m*/ final int scale = 100; final JSlider limitSlider = new JSlider(); limitSlider.setMinimum(0); limitSlider.setMaximum(scale); limitSlider.setValue((int) (limit * scale)); final JTextField limitText = new JTextField(); limitText.setEditable(false); limitText.setText("" + limit); limitSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { limit = limitSlider.getValue() / (double) scale; limitText.setText("" + limit); v.settingsChanged(false); } }); JPanel ret = new JPanel(); GridBagLayout bag = new GridBagLayout(); ret.setLayout(bag); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = c.HORIZONTAL; ret.add(limitSlider, c); c.gridy++; ret.add(limitText, c); return ret; }
From source file:com.sec.ose.osi.ui.frm.main.identification.common.JComboComponentName.java
public void setComponentName(String pComponentName) { log.debug("setComponentName() - pComponentName : " + pComponentName); JTextField editor = (JTextField) this.getEditor().getEditorComponent(); if (this != null) { editor.setText(pComponentName); }/*www . j a v a2s . c o m*/ }
From source file:edu.harvard.mcz.imagecapture.ui.FilteringAgentJComboBox.java
public void focusGained(FocusEvent e) { super.getModel().setSelectedItem(""); JTextField textfield = (JTextField) this.getEditor().getEditorComponent(); textfield.setText(""); }
From source file:ToolBarDemo2.java
public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); String description = null;//from w w w . j av a 2 s . com // Handle each button. if (PREVIOUS.equals(cmd)) { //first button clicked description = "taken you to the previous <something>."; } else if (UP.equals(cmd)) { // second button clicked description = "taken you up one level to <something>."; } else if (NEXT.equals(cmd)) { // third button clicked description = "taken you to the next <something>."; } else if (SOMETHING_ELSE.equals(cmd)) { // fourth button clicked description = "done something else."; } else if (TEXT_ENTERED.equals(cmd)) { // text field JTextField tf = (JTextField) e.getSource(); String text = tf.getText(); tf.setText(""); description = "done something with this text: " + newline + " \"" + text + "\""; } displayResult("If this were a real app, it would have " + description); }
From source file:net.fenyo.gnetwatch.GUI.AwtGUI.java
public void createDialog() { try {/*from w w w .ja v a 2 s.c om*/ javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { final JTextField button = new JTextField(); button.setText("close this window to stop the foreground action"); final JFrame frame = new JFrame("working..."); frame.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { // XXX } }); frame.getContentPane().add(button, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); frame.toFront(); } }); } catch (final InvocationTargetException ex) { log.error("exception", ex); } catch (final InterruptedException ex) { log.error("exception", ex); } }
From source file:br.com.pontocontrol.controleponto.util.SwingUtils.java
public static void validateDateFields(JTextField... fields) { for (JTextField field : fields) { Calendar dataDoCampo = null; Calendar dataSaida = Calendar.getInstance(); try {// w ww .j av a 2 s . co m dataDoCampo = getCalendarValueFromField(SIMPLE_DATE_FORMATTER_A, field); dataSaida = dataDoCampo; } catch (ParseException ex) { try { dataDoCampo = getCalendarValueFromField(SIMPLE_DATE_FORMATTER_B, field); dataSaida.set(Calendar.DAY_OF_MONTH, dataDoCampo.get(Calendar.DAY_OF_MONTH)); dataSaida.set(Calendar.MONTH, dataDoCampo.get(Calendar.MONTH)); } catch (ParseException ex1) { try { dataDoCampo = getCalendarValueFromField(SIMPLE_DATE_FORMATTER_C, field); dataSaida.set(Calendar.DAY_OF_MONTH, dataDoCampo.get(Calendar.DAY_OF_MONTH)); } catch (ParseException ex2) { } } } if (dataDoCampo != null) { String valTxt = SIMPLE_DATE_FORMATTER_A.format(dataSaida.getTime()); field.setText(valTxt); } else { field.setText(""); } } }
From source file:edu.smc.mediacommons.panels.SecurityPanel.java
public SecurityPanel() { setLayout(null);//from w ww . ja va 2s. c o m FILE_CHOOSER = new JFileChooser(); JButton openFile = Utils.createButton("Open File", 10, 20, 100, 30, null); add(openFile); JButton saveFile = Utils.createButton("Save File", 110, 20, 100, 30, null); add(saveFile); JButton decrypt = Utils.createButton("Decrypt", 210, 20, 100, 30, null); add(decrypt); JButton encrypt = Utils.createButton("Encrypt", 310, 20, 100, 30, null); add(encrypt); JTextField path = Utils.createTextField(10, 30, 300, 20); path.setText("No file selected"); final JTextArea viewer = new JTextArea(); JScrollPane pastePane = new JScrollPane(viewer); pastePane.setBounds(15, 60, 400, 200); add(pastePane); openFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (FILE_CHOOSER.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { File toRead = FILE_CHOOSER.getSelectedFile(); if (toRead == null) { JOptionPane.showMessageDialog(getParent(), "The input file does not exist!", "Opening Failed...", JOptionPane.WARNING_MESSAGE); } else { try { List<String> lines = IOUtils.readLines(new FileInputStream(toRead), "UTF-8"); viewer.setText(""); for (String line : lines) { viewer.append(line); } } catch (IOException ex) { } } } } }); saveFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (FILE_CHOOSER.showSaveDialog(getParent()) == JFileChooser.APPROVE_OPTION) { File toWrite = FILE_CHOOSER.getSelectedFile(); Utils.writeToFile(viewer.getText(), toWrite); JOptionPane.showMessageDialog(getParent(), "The file has now been saved to\n" + toWrite.getPath()); } } }); encrypt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String password = Utils.getPasswordInput(getParent()); if (password != null) { try { BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor(); basicTextEncryptor.setPassword(password); String text = basicTextEncryptor.encrypt(viewer.getText()); viewer.setText(text); } catch (Exception ex) { JOptionPane.showMessageDialog(getParent(), "Could not encrypt the text, an unexpected error occurred.", "Encryption Failed...", JOptionPane.WARNING_MESSAGE); } } else { JOptionPane.showMessageDialog(getParent(), "Could not encrypt the text, as no\npassword has been specified.", "Encryption Failed...", JOptionPane.WARNING_MESSAGE); } } }); decrypt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String password = Utils.getPasswordInput(getParent()); if (password != null) { try { BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor(); basicTextEncryptor.setPassword(password); String text = basicTextEncryptor.decrypt(viewer.getText()); viewer.setText(text); } catch (Exception ex) { JOptionPane.showMessageDialog(getParent(), "Could not decrypt the text, an unexpected error occurred.", "Decryption Failed...", JOptionPane.WARNING_MESSAGE); } } else { JOptionPane.showMessageDialog(getParent(), "Could not decrypt the text, as no\npassword has been specified.", "Decryption Failed...", JOptionPane.WARNING_MESSAGE); } } }); }
From source file:king.flow.action.business.InsertCardAction.java
private void showOnComponent(int componentId, String value) { Component meta = (Component) getBlockMeta(componentId); getLogger(InsertCardAction.class.getName()).log(Level.INFO, "Display component[{0}] type : {1}", new Object[] { String.valueOf(meta.getId()), meta.getType().value() }); switch (meta.getType()) { case LABEL:// www. j a v a2 s .c o m JLabel label = getBlock(meta.getId(), JLabel.class); label.setText(StringEscapeUtils.unescapeHtml(value)); break; case TEXT_FIELD: JTextField textField = getBlock(meta.getId(), JTextField.class); textField.setText(value); break; case COMBO_BOX: JComboBox combo = getBlock(meta.getId(), JComboBox.class); if (combo.isEditable()) { combo.getEditor().setItem(value); } break; default: getLogger(InsertCardAction.class.getName()).log(Level.WARNING, "Unsupported showed component type : {0}", meta.getType()); } }