List of usage examples for javax.swing JTextField getDocument
public Document getDocument()
From source file:Main.java
public Main() { JButton button = new JButton("foo"); JTextField textField = new JTextField(10); Document document = textField.getDocument(); document.addDocumentListener(new JButtonStateController(button)); JOptionPane.showMessageDialog(null, textField); }
From source file:Main.java
public Main() { JButton button = new JButton("foo"); JTextField textField = new JTextField(10); Document document = textField.getDocument(); document.addDocumentListener(new JButtonStateController(button)); JFrame frame = new JFrame(); frame.add(button, BorderLayout.WEST); frame.add(textField, BorderLayout.CENTER); frame.setSize(300, 300);/*from ww w . j a v a 2s . c o m*/ frame.setVisible(true); }
From source file:Main.java
public Main() throws HeadlessException { setSize(200, 200);//from w ww. java 2s. c om setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout(FlowLayout.LEFT)); DocumentFilter filter = new UppercaseDocumentFilter(); JTextField firstName = new JTextField(); firstName.setPreferredSize(new Dimension(100, 20)); ((AbstractDocument) firstName.getDocument()).setDocumentFilter(filter); JTextField lastName = new JTextField(); lastName.setPreferredSize(new Dimension(100, 20)); ((AbstractDocument) lastName.getDocument()).setDocumentFilter(filter); add(firstName); add(lastName); }
From source file:biomine.bmvis2.pipeline.TextFilterShower.java
public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { JPanel ret = new JPanel(); final JTextField filterField = new JTextField(); ret.add(filterField);/* w w w . j av a 2 s.c o m*/ filterField.getDocument().addDocumentListener(new DocumentListener() { private void update() { if (filterField.getText().equals("")) return; if (filterField.getText().equals(TextFilterShower.this.filter)) return; TextFilterShower.this.filter = filterField.getText(); v.settingsChanged(false); } public void insertUpdate(DocumentEvent documentEvent) { this.update(); } public void removeUpdate(DocumentEvent documentEvent) { this.update(); } public void changedUpdate(DocumentEvent documentEvent) { this.update(); } }); return ret; }
From source file:biomine.bmvis2.pipeline.TextFilterHider.java
public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { JPanel ret = new JPanel(); final JTextField filterField = new JTextField(); ret.add(filterField);/* w w w . j ava2s.c om*/ filterField.getDocument().addDocumentListener(new DocumentListener() { private void update() { if (filterField.getText().equals("")) return; if (filterField.getText().equals(TextFilterHider.this.filter)) return; TextFilterHider.this.filter = filterField.getText(); v.settingsChanged(false); } public void insertUpdate(DocumentEvent documentEvent) { this.update(); } public void removeUpdate(DocumentEvent documentEvent) { this.update(); } public void changedUpdate(DocumentEvent documentEvent) { this.update(); } }); return ret; }
From source file:fr.free.hd.servers.gui.PhonemView.java
@Override protected JComponent createControl() { final JPanel view = new JPanel(new BorderLayout()); Collection<Phonem> phonesList = phonemsDAO.getPhonems(); Map<String, Phonem> mapList = new HashMap<String, Phonem>(); for (Phonem phonem : phonesList) { mapList.put(phonem.getPhonem(), phonem); }/* ww w .j ava 2s . c o m*/ final StatementListModel model = new StatementListModel(mapList); printCommand.setModel(model); printCommand.setFace(face); copyCommand.setModel(model); copyCommand.setFace(face); list = new JList(model); final JScrollPane sp = new JScrollPane(list); final JTextField field = new JTextField(); field.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { model.setString(field.getText()); } @Override public void insertUpdate(DocumentEvent e) { model.setString(field.getText()); } @Override public void removeUpdate(DocumentEvent e) { model.setString(field.getText()); } }); final PhonemListModel phonemModel = new PhonemListModel((List<Phonem>) phonesList); final JList phonemList = new JList(phonemModel); final JScrollPane spPhonemList = new JScrollPane(phonemList); phonemList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { // private int oldIndex = -1; @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { Phonem innerPhonem = (Phonem) phonemModel.getElementAt(phonemList.getSelectedIndex()); field.setText(field.getText() + innerPhonem.getPhonem()); } } }); phonemList.setCellRenderer(new PhonemListRenderer()); list.setCellRenderer(new StatementPhonemListRenderer(face)); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setLayoutOrientation(JList.HORIZONTAL_WRAP); list.setVisibleRowCount(1); view.add(spPhonemList, BorderLayout.WEST); view.add(sp, BorderLayout.CENTER); view.add(field, BorderLayout.SOUTH); field.requestFocus(); return view; }
From source file:at.beris.jarcommander.helper.ModelViewController.java
public void unregisterObjectWithModelProperty(Component component, String modelPropertyName) { Method modelGetPropertyMethod = getPropertyGetter(model, modelPropertyName); List<Component> componentList = modelGetPropertyMethodToViewFieldsMap.get(modelGetPropertyMethod); while (componentList.size() > 0) { component = componentList.get(componentList.size() - 1); if (component instanceof JTextField) { JTextField textField = (JTextField) component; textField.getDocument().removeDocumentListener(documentListenerMap.get(component)); documentListenerMap.remove(component); }/*from w ww. j av a2 s . co m*/ componentList.remove(componentList.size() - 1); } modelGetPropertyMethodToViewFieldsMap.remove(modelGetPropertyMethod); }
From source file:TextCutPaste.java
/** * Bundle up the data for export./*w ww . j a v a 2 s . co m*/ */ protected Transferable createTransferable(JComponent c) { JTextField source = (JTextField) c; int start = source.getSelectionStart(); int end = source.getSelectionEnd(); Document doc = source.getDocument(); if (start == end) { return null; } try { p0 = doc.createPosition(start); p1 = doc.createPosition(end); } catch (BadLocationException e) { System.out.println("Can't create position - unable to remove text from source."); } String data = source.getSelectedText(); return new StringSelection(data); }
From source file:edu.ku.brc.specify.config.init.RegisterSpecify.java
/** * Registers the ISA number.// w w w. j a v a 2s . c o m */ 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:eu.europa.ec.markt.tlmanager.view.binding.BindingManager.java
/** * Determine bean property for a component and sets it up with appropriate listeners. * /*from w ww . jav a2 s .com*/ * @param component the component * * @return the bean property */ private BeanProperty setupComponent(final JComponent component) { if (component instanceof JTextField) { final JTextField tf = (JTextField) component; tf.getDocument().addDocumentListener(new DefaultDocumentListener() { @Override protected void changed() { if (component.getParent() instanceof JComboBox) { JComboBox comboBox = (JComboBox) component.getParent(); labelHandler.handleLabelStateFor(comboBox, Util.DEFAULT_NO_SELECTION_ENTRY.equals(tf.getText())); } else { labelHandler.handleLabelStateFor(component, StringUtils.isEmpty(tf.getText())); } labelHandler.handleLabelStateFor(component, tf.getText().isEmpty()); } }); return BP_TEXT; } else if (component instanceof JComboBox) { final JComboBox box = (JComboBox) component; addListenerForEditableCombobox(box, new EditableComboboxListener() { @Override public void itemChanged(Object item) { labelHandler.handleLabelStateFor(component, Util.DEFAULT_NO_SELECTION_ENTRY.equals(item)); } }); return BP_COMBO; } else if (component instanceof MultivaluePanel) { return BP_MVALUE; } else if (component instanceof JXDatePicker) { final JXDatePicker picker = (JXDatePicker) component; picker.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (picker.getDate() != null) { labelHandler.handleLabelStateFor(component, false); } else { labelHandler.handleLabelStateFor(component, true); } } }); return BP_DATEPICKER; } else if (component instanceof DateTimePicker) { final DateTimePicker picker = (DateTimePicker) component; picker.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (picker.getDateTime() != null) { labelHandler.handleLabelStateFor(component, false); } else { labelHandler.handleLabelStateFor(component, true); } } }); return BP_DATETIMEPICKER; } else if (component instanceof JCheckBox) { return BP_CHECKBOX; } else if (component instanceof CertificateProperty) { return BP_CERTIFICATE_PROPERTY; } return null; }