List of utility methods to do JTextComponent
Dimension | getPreferredScrollableViewportSize(javax.swing.text.JTextComponent t, Dimension ans) Returns the preferred size of the viewport for component 't'. java.awt.Container p = t.getParent(); if (p instanceof javax.swing.JViewport) { p = p.getParent(); if (p instanceof javax.swing.JScrollPane) shrink(ans, p.getMaximumSize()); return ans; |
int | getRenderedLineOfChar(JTextComponent comp, int charIdx) Determines the displayed line on which a given character is rendered on a JTextComponent. int charCount = 0; int lineCount = 0; View document = comp.getUI().getRootView(comp).getView(0); if (document != null) { for (int paragraphIdx = 0; paragraphIdx < document.getViewCount(); paragraphIdx++) { View paragraph = document.getView(paragraphIdx); for (int lineIdx = 0; lineIdx < paragraph.getViewCount(); lineIdx++) { View line = paragraph.getView(lineIdx); ... |
Color | getStoredBackground(JTextComponent comp) Returns the background color that has been previously stored for the given component, or null if none.
return (Color) comp.getClientProperty(STORED_BACKGROUND_KEY);
|
Color | getStoredBackground(JTextComponent comp) Returns the background color that has been previously stored for the given component, or null if none.
return (Color) comp.getClientProperty(STORED_BACKGROUND_KEY);
|
boolean | highlighterIsNext(JTextComponent textComponent, boolean forwards, Highlighter.Highlight highlight) highlighter Is Next final int minOffset = Math.min(highlight.getStartOffset(), highlight.getEndOffset()); final int maxOffset = Math.max(highlight.getStartOffset(), highlight.getEndOffset()); if (forwards) { return minOffset > textComponent.getSelectionEnd(); } else { return maxOffset < textComponent.getSelectionStart(); |
void | implyDisabled(final JCheckBox checked, final boolean checkedState, final JTextComponent changed) Checks state of the checked checkbox and if state is checkedState than to disable changed text field and clean it. ActionListener l = new ActionListener() { String previousState; public void actionPerformed(ActionEvent e) { if (checked.isSelected() == checkedState) { if (previousState == null) { previousState = changed.getText(); changed.setEnabled(false); ... |
JScrollPane | inScrollPane(JTextComponent textComponent, boolean autoscroll) in Scroll Pane JScrollPane pane = new JScrollPane(textComponent); if (autoscroll) { DefaultCaret caret = (DefaultCaret) textComponent.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); pane.setAutoscrolls(true); return pane; |
void | installUi(JTextComponent txt) Install the border txt.setOpaque(false); Insets margin = txt.getMargin(); if (margin == null) { margin = new Insets(5, 5, 5, 5); Border marginBorder = BorderFactory.createEmptyBorder(margin.top + 3, margin.left, margin.bottom + 3, margin.right); CompoundBorder border = new CompoundBorder(BorderFactory.createLineBorder(Color.WHITE), marginBorder); ... |
void | installUndoManager(JTextComponent textComponent) install Undo Manager installUndoManager(textComponent, new UndoManager());
|
boolean | isCompletelyVisible(final JTextComponent scrollableComponent, final int pos, final Rectangle visibleRect) is Completely Visible Rectangle r = modelToView(scrollableComponent, pos);
return intersects(r, visibleRect);
|