int pos2 = textArea.getText().indexOf(turnToString2); Rectangle startIndex = textArea.modelToView(pos2); textArea.getHighlighter().addHighlight(pos2, pos2 + turnToString2.length(), new DefaultHighlighter.DefaultHighlightPainter(Color.yellow));
Highlighter highlighter = tarea.getHighlighter(); highlighter.removeHighlight(highlights.get(startIndex)); tarea.setCaretPosition(startIndex); Highlighter highlighter = tarea.getHighlighter();
/** * Constructor. * @param textComponent JTextComponent that is to be searched. * @param painter Highlighter.HighlightPainter instance to paint the highlights. */ SearchEngine(JTextComponent textComponent, Highlighter.HighlightPainter painter) { this.document = textComponent.getDocument(); this.highlighter = textComponent.getHighlighter(); this.painter = painter; }
@Override public void componentHidden(ComponentEvent componentEvent) { textComponent.getHighlighter().removeAllHighlights(); }
private void search(DocumentEvent documentEvent) { try { String word = documentEvent.getDocument().getText(0, documentEvent.getDocument().getLength()); if (word.isEmpty()) { nextAction.setEnabled(false); previousAction.setEnabled(false); searchPanel.reset(); textComponent.getHighlighter().removeAllHighlights(); return; } search(word); } catch (BadLocationException e) { e.printStackTrace(); } }
redPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.red); try { textPane.getHighlighter().addHighlight(0, 3, DefaultHighlighter.DefaultPainter); textPane.getHighlighter().addHighlight(8, 14, cyanPainter); textPane.getHighlighter().addHighlight(19, 24, redPainter); } catch (BadLocationException ble) {
tarea.getHighlighter().addHighlight(startIndex, endIndex, painter); tarea.getHighlighter().addHighlight(startIndex, endIndex, painter); tarea.getHighlighter().addHighlight(startIndex, endIndex, painter);
private void changeHighlighter(int index, Highlighter.HighlightPainter newPainter) { Highlighter highlighter = textComponent.getHighlighter(); Highlighter.Highlight highLight = highlights.get(index); highlighter.removeHighlight(highLight); try { highlighter.addHighlight(highLight.getStartOffset(), highLight.getEndOffset(), newPainter); highlights.set(index, highlighter.getHighlights()[highlighter.getHighlights().length - 1]); } catch (BadLocationException e) { e.printStackTrace(); } }
jta.getHighlighter().addHighlight(1, _lenght - 1, cyanPainter); } catch (BadLocationException bla_bla_bla_bla) { jta.getHighlighter().addHighlight(1, _lenght - 1, redPainter); } catch (BadLocationException bla_bla_bla_bla) { jta.getHighlighter().addHighlight(1, _lenght - 1, whitePainter); } catch (BadLocationException bla_bla_bla_bla) {
JTextComponent editor = //... your editor component; SquiggleUnderlineHighlightPainter sqpainter = new SquiggleUnderlineHighlightPainter(Color.RED); try { editor.getHighlighter().addHighlight(beginPosition, endPosition, sqpainter); } catch (BadLocationException e) { e.printStackTrace(); }
public List<Highlight> getParameterHighlights() { List<Highlight> paramHighlights = new ArrayList<Highlight>(2); JTextComponent tc = ac.getTextComponent(); Highlight[] highlights = tc.getHighlighter().getHighlights(); for (int i=0; i<highlights.length; i++) { HighlightPainter painter = highlights[i].getPainter(); if (painter==p || painter==endingP) { paramHighlights.add(highlights[i]); } } return paramHighlights; }
/** * Removes all highlights from the text component. */ protected void removeAllHighlights() { if (_component instanceof JTextComponent) { Iterator itor = _highlighCache.getAllHighlights(); while (itor.hasNext()) { Object o = itor.next(); ((JTextComponent) _component).getHighlighter().removeHighlight(o); } _highlighCache.removeAllHighlights(); } }
public void removeHighlights(JTextComponent c, String toBlackOut) { Highlighter highlighter = c.getHighlighter(); Highlighter.Highlight[] highlights = h.getHighlights(); Document d = c.getDocument(); for (Highlighter.Highlight h : highlights) if (highlightedText(h, d).equals(toBlackOut) && h.getPainter() instanceof TextHighLighter) highlighter.removeHighlight(h); }
protected void highlight(JTextComponent comp, int i, int j) { Highlighter highlighter = comp.getHighlighter(); highlighter.removeAllHighlights(); try { highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter); } catch (BadLocationException ble) { errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble); } }
private void paintHighlights(Graphics g, Shape shape) { if (container instanceof JTextComponent) { JTextComponent tc = (JTextComponent) container; Highlighter h = tc.getHighlighter(); if (h instanceof LayeredHighlighter) { ((LayeredHighlighter) h).paintLayeredHighlights(g, getStartOffset(), getEndOffset(), shape, tc, this); } } }
public void removeHighlights(JTextComponent textComonent) { Highlighter hilite = textComonent.getHighlighter(); for (Highlighter.Highlight highlight : hilite.getHighlights()) { if (highlight.getPainter() instanceof SearchHighlightPainter) { hilite.removeHighlight(highlight); } } }
void switchHighlight(boolean on) { if (!on) { highlight(tc, true); } if (currentComp != null) { try { currentComp.getHighlighter().addHighlight(currentStart, currentEnd, highlighterCurrent); } catch (BadLocationException blex) { BugtrackingManager.LOG.log(Level.INFO, blex.getMessage(), blex); } } if (on) { highlight(tc, false); } }
private void removeHighlights() { JTextComponent editorComponent = _editor.getEditor(); Highlighter highlighter = editorComponent.getHighlighter(); // Always clean up previous underlines Highlighter.Highlight[] highlights = highlighter.getHighlights(); for( Highlighter.Highlight highlight : highlights ) { if( highlight.getPainter() == PAINTER ) { highlighter.removeHighlight( highlight ); } } }
public LinePainter(JTextComponent component, Color color) { this.component = component; setColor(color); // Add listeners so we know when to change highlighting component.addCaretListener(this); component.addMouseListener(this); component.addMouseMotionListener(this); // Turn highlighting on by adding a dummy highlight try { component.getHighlighter().addHighlight(0, 0, this); } catch (BadLocationException ble) { } }
/** * Installs CurrentLineHilighter for the given JTextComponent. * @param c is the text component */ public static void install(JTextComponent c) { try { Object obj = c.getHighlighter().addHighlight(0, 0, painter); c.putClientProperty(LINE_HIGHLIGHT, obj); c.putClientProperty(PREVIOUS_CARET, new Integer(c.getCaretPosition())); c.addCaretListener(caretListener); c.addMouseListener(mouseListener); c.addMouseMotionListener(mouseMotionListener); color = EditorThemePropertiesManager.getCurrentEditorThemeProperties().getHighlightedLineColor(); EditorThemePropertiesManager.addListener(editorThemePropertyChangeListener); } catch (BadLocationException ex) {} }