@Override public void insertUpdate(DocumentEvent e) { try { // Check for change in lines only if a newline // character is inserted. String insertion = e.getDocument().getText(e.getOffset(), e.getLength()); if (insertion.contains("\n")) documentChanged(); } catch (BadLocationException ex) { /* nothing to do */ } }
void updateTheLabel(DocumentEvent e) { Document doc = (Document) e.getDocument(); String text = null; try { text = doc.getText(0, doc.getLength()); doc = null; } catch (BadLocationException ex) { text = null; } if (text != null) { try { double number = Double.parseDouble(text); if (number > 1) { label.setText(labelPair.getPlural()); } else { label.setText(labelPair.getSingular()); } } catch (NumberFormatException ex) { // Do nothing } finally { text = null; } } }