List of utility methods to do JTextComponent
void | readOnly(JTextComponent c, Component parent) read Only c.setEditable(false); c.setForeground(parent.getForeground()); c.setBackground(parent.getBackground()); |
void | refreshJTextComponent(JTextComponent textComponent) refresh J Text Component int pos = textComponent.getCaretPosition(); textComponent.setText(textComponent.getText()); textComponent.validate(); try { textComponent.setCaretPosition(pos); } catch (IllegalArgumentException e) { System.err.println(e.getMessage()); |
void | registerEvents(final JTextComponent textCmp, final String hintText) register Events textCmp.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { if (textCmp.getText().equals(hintText)) { textCmp.setText(""); public void focusLost(FocusEvent e) { }); |
void | registerUpperCase(final JTextComponent textComp) register Upper Case textComp.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { textComp.setText(textComp.getText().toUpperCase()); }); |
void | removeAllHighlightsUsingPainter(final JTextComponent textComponent, final Highlighter.HighlightPainter painter) remove All Highlights Using Painter Highlighter highlighter = textComponent.getHighlighter(); for (Highlighter.Highlight highlight : highlighter.getHighlights()) { if (highlight.getPainter() == painter) { highlighter.removeHighlight(highlight); |
void | removeDocumentListeners(JTextComponent component) Remove all document listeners from this text component Document document = component.getDocument(); if (document instanceof AbstractDocument) { DocumentListener[] dls = ((AbstractDocument) document).getDocumentListeners(); for (int i = 0; i < dls.length; i++) { ((AbstractDocument) document).removeDocumentListener(dls[i]); UndoableEditListener[] uels = ((AbstractDocument) document).getUndoableEditListeners(); for (int i = 0; i < uels.length; i++) { ... |
String | safeGetText(JTextComponent textComponent) Gets the "text" contents of a JTextComponent without the possibility of a NullPointerException . String value = ""; if ((textComponent != null) && (textComponent.getText() != null)) { value = textComponent.getText(); return value; |
void | scrollToText(JTextComponent textComponent, int startingIndex, int endingIndex) Scrolls the specified text component so the text between the starting and ending index are visible. try { Rectangle startingRectangle = textComponent.modelToView(startingIndex); Rectangle endDingRectangle = textComponent.modelToView(endingIndex); Rectangle totalBounds = startingRectangle.union(endDingRectangle); textComponent.scrollRectToVisible(totalBounds); textComponent.repaint(); } catch (BadLocationException e) { e.printStackTrace(); ... |
void | scrollToTop(JTextComponent edit1) scroll To Top edit1.setCaretPosition(0); |
void | setError(JTextComponent component, boolean error) set Error component.setBackground(error ? ERROR_BG : NORMAL_BG); |