List of usage examples for javax.swing.event DocumentListener DocumentListener
DocumentListener
From source file:Main.java
public static void onTextFieldChange(JTextField field, final Runnable task) { field.getDocument().addDocumentListener(new DocumentListener() { @Override//from w w w. j a v a 2s . c o m public void insertUpdate(DocumentEvent e) { task.run(); } @Override public void removeUpdate(DocumentEvent e) { task.run(); } @Override public void changedUpdate(DocumentEvent e) { task.run(); } }); }
From source file:Main.java
public static void addTextUpdateListener(JTextComponent textComponent, Consumer<DocumentEvent> listener) { Document doc = textComponent.getDocument(); doc.addDocumentListener(new DocumentListener() { @Override//from ww w . j a v a 2s .com public void removeUpdate(DocumentEvent e) { listener.accept(e); } @Override public void insertUpdate(DocumentEvent e) { listener.accept(e); } @Override public void changedUpdate(DocumentEvent e) { listener.accept(e); } }); }
From source file:Main.java
public Main() { textArea.getDocument().addDocumentListener(new DocumentListener() { @Override//from w ww . j a va 2 s. co m public void changedUpdate(DocumentEvent e) { update(e); } @Override public void insertUpdate(DocumentEvent e) { update(e); } @Override public void removeUpdate(DocumentEvent e) { update(e); } private void update(DocumentEvent e) { List<String> lines = getLines(textArea); String lastLine = lines.get(lines.size() - 1); int tabbedTextWidth = Utilities.getTabbedTextWidth( new Segment(lastLine.toCharArray(), 0, lastLine.length()), textArea.getFontMetrics(textArea.getFont()), 0, null, 0); int lineHeight = getLineHeight(textArea); if (lines.size() * lineHeight > textArea.getHeight() || tabbedTextWidth > textArea.getWidth()) { System.out.println("Too many lines!"); } } }); getContentPane().add(textArea); }
From source file:Main.java
public Main() { listener = new DocumentListener() { Document source = null;/*from w w w. ja v a2s. com*/ protected void update(Document doc) { if (source == null) { System.out.println("Update"); source = doc; if (source.equals(input.getDocument())) { input2.setText(input.getText()); } else if (source.equals(input2.getDocument())) { input.setText(input2.getText()); } source = null; } } @Override public void insertUpdate(DocumentEvent e) { update(e.getDocument()); } @Override public void removeUpdate(DocumentEvent e) { update(e.getDocument()); } @Override public void changedUpdate(DocumentEvent e) { update(e.getDocument()); } }; input.getDocument().addDocumentListener(listener); input2.getDocument().addDocumentListener(listener); input.setColumns(4); input2.setColumns(4); input.setValue(0.0); JPanel panel = new JPanel(); panel.add(input); panel.add(input2); JOptionPane.showMessageDialog(null, panel); }
From source file:com.mirth.connect.client.ui.editors.ScriptPanel.java
public ScriptPanel(MirthEditorPane p, TokenMarker tokenMarker) { super();/*w ww.j a v a2 s . co m*/ parent = p; initComponents(); scriptTextPane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { } public void insertUpdate(DocumentEvent arg0) { parent.modified = true; } public void removeUpdate(DocumentEvent arg0) { parent.modified = true; } }); }
From source file:com.mirth.connect.client.ui.editors.ExternalScriptPanel.java
public ExternalScriptPanel(MirthEditorPane p, boolean step) { parent = p;/*from w w w.j av a 2 s. c o m*/ isStep = step; initComponents(); variableTextField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { } public void insertUpdate(DocumentEvent arg0) { if (isStep) { updateTable(); } parent.modified = true; } public void removeUpdate(DocumentEvent arg0) { if (isStep) { updateTable(); } parent.modified = true; } }); }
From source file:Main.java
private void initComponents() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane textPane = new JTextPane(); ((AbstractDocument) textPane.getDocument()).addDocumentListener(new DocumentListener() { @Override//from w w w . j a va 2 s .c om public void insertUpdate(final DocumentEvent de) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { StyledDocument doc = (StyledDocument) de.getDocument(); int start = Utilities.getRowStart(textPane, Math.max(0, de.getOffset() - 1)); int end = Utilities.getWordStart(textPane, de.getOffset() + de.getLength()); String text = doc.getText(start, end - start); for (String emoticon : imageTokens) { int i = text.indexOf(emoticon); while (i >= 0) { final SimpleAttributeSet attrs = new SimpleAttributeSet( doc.getCharacterElement(start + i).getAttributes()); if (StyleConstants.getIcon(attrs) == null) { switch (emoticon) { case imageToken: StyleConstants.setIcon(attrs, anImage); break; } doc.remove(start + i, emoticon.length()); doc.insertString(start + i, emoticon, attrs); } i = text.indexOf(emoticon, i + emoticon.length()); } } } catch (BadLocationException ex) { ex.printStackTrace(); } } }); } @Override public void removeUpdate(DocumentEvent e) { } @Override public void changedUpdate(DocumentEvent e) { } }); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(300, 300)); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }
From source file:com.mirth.connect.client.ui.editors.XsltStepPanel.java
public XsltStepPanel(MirthEditorPane p) { parent = p;/*w ww . j a v a 2 s .c o m*/ initComponents(); sourceVariableField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { } public void insertUpdate(DocumentEvent arg0) { updateTable(); parent.modified = true; } public void removeUpdate(DocumentEvent arg0) { updateTable(); parent.modified = true; } }); resultVariableField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { } public void insertUpdate(DocumentEvent arg0) { parent.modified = true; } public void removeUpdate(DocumentEvent arg0) { parent.modified = true; } }); mappingDoc = new SyntaxDocument(); mappingDoc.setTokenMarker(new XMLTokenMarker()); xsltTemplateTextPane.setDocument(mappingDoc); }
From source file:com.aw.swing.mvp.cmp.RowSelectorMediator.java
public RowSelectorMediator(JTextField textField, JTable table, int columnIndex) { this.textField = textField; this.table = table; this.columnIndex = columnIndex; documentListener = new DocumentListener() { public void changedUpdate(DocumentEvent e) { textFieldChanged(e);/*from w ww .j av a 2s.co m*/ } public void insertUpdate(DocumentEvent e) { textFieldChanged(e); } public void removeUpdate(DocumentEvent e) { textFieldChanged(e); } }; textField.getDocument().addDocumentListener(documentListener); //Add the keylistener to process the Up, Down, PgUp and PgDn keys events textField.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { textFieldKeyPressed(e); } public void keyReleased(KeyEvent e) { } }); }
From source file:bazaar4idea.ui.BzrTagDialog.java
public BzrTagDialog(Project project) { super(project, false); hgRepositorySelectorComponent.setTitle("Select repository to tag"); DocumentListener documentListener = new DocumentListener() { public void insertUpdate(DocumentEvent e) { update();//from w w w. j av a 2 s . c om } public void removeUpdate(DocumentEvent e) { update(); } public void changedUpdate(DocumentEvent e) { update(); } }; tagTxt.getDocument().addDocumentListener(documentListener); setTitle("Tag"); init(); }