List of utility methods to do JTextComponent
void | currentLineChanged(final JTextComponent c) Fetches the previous caret location, stores the current caret location. if (null == c.getClientProperty(PREVIOUS_CARET)) { return; try { final int previousCaret = ((Integer) c.getClientProperty(PREVIOUS_CARET)).intValue(); final Rectangle prev = c.modelToView(previousCaret); final Rectangle r = c.modelToView(c.getCaretPosition()); c.putClientProperty(PREVIOUS_CARET, new Integer(c.getCaretPosition())); ... |
void | enableJTextField(JTextComponent component, boolean enable, Color color) enable J Text Field component.setEnabled(enable); component.setEditable(enable); component.setBackground(color); component.invalidate(); component.validate(); component.repaint(1); |
void | ensureCustomBackgroundStored(JTextComponent comp) Ensures that a text component's custom background - if any - is stored as a client property. if (getStoredBackground(comp) != null) return; Color background = comp.getBackground(); if ((background == null) || (background instanceof UIResource) || (background == WARNING_BACKGROUND) || (background == ERROR_BACKGROUND)) return; comp.putClientProperty(STORED_BACKGROUND_KEY, background); |
void | ensureCustomBackgroundStored(JTextComponent comp) Ensures that a text component's custom background - if any - is stored as a client property. if (getStoredBackground(comp) != null) return; Color background = comp.getBackground(); if ((background == null) || (background instanceof UIResource) || (background == WARNING_BACKGROUND) || (background == ERROR_BACKGROUND)) return; comp.putClientProperty(STORED_BACKGROUND_KEY, background); |
void | fillWith(String value, JTextComponent... fields) fill With for (JTextComponent field : fields) {
field.setText(value);
|
int | getAdjustedClickCount(JTextComponent comp, MouseEvent e) Return the MouseEvent's click count, possibly reduced by the value of the component's SKIP_CLICK_COUNT client property. int cc = e.getClickCount(); if (cc == 1) { comp.putClientProperty(SKIP_CLICK_COUNT, null); } else { Integer sub = (Integer) comp.getClientProperty(SKIP_CLICK_COUNT); if (sub != null) { return cc - sub; return cc; |
String | getCurrentTextBlock(JTextComponent textComponent) this method will get the current block of text that the caret is within. String patternStr = "(?m)^\\s*?$"; Pattern pattern = Pattern.compile(patternStr); String text = textComponent.getText(); Matcher matcher = pattern.matcher(text); int caretPosition = textComponent.getCaretPosition(); int prevBlankLineIndex = 0; while (matcher.find()) { if (matcher.start() >= caretPosition) ... |
int | getNumberOfLines(final JTextComponent component) get Number Of Lines final Element root = component.getDocument().getDefaultRootElement(); return root.getElementCount(); |
Element | getParagraphElement(JTextComponent c, int offs) Determines the element to use for a paragraph/line. Document doc = c.getDocument(); if (doc instanceof StyledDocument) { return ((StyledDocument) doc).getParagraphElement(offs); Element map = doc.getDefaultRootElement(); int index = map.getElementIndex(offs); Element paragraph = map.getElement(index); if ((offs >= paragraph.getStartOffset()) && (offs < paragraph.getEndOffset())) { ... |
int | getPositionBelow(JTextComponent c, int offs, int x) Determines the position in the model that is closest to the given view location in the row below. int lastOffs = getRowEnd(c, offs) + 1; if (lastOffs <= 0) { return -1; int bestSpan = Short.MAX_VALUE; int n = c.getDocument().getLength(); int y = 0; Rectangle r = null; ... |