javax.swing.text.JTextComponent.getHighlighter()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中javax.swing.text.JTextComponent.getHighlighter()方法的一些代码示例,展示了JTextComponent.getHighlighter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextComponent.getHighlighter()方法的具体详情如下:
包路径:javax.swing.text.JTextComponent
类名称:JTextComponent
方法名:getHighlighter

JTextComponent.getHighlighter介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

int pos2 = textArea.getText().indexOf(turnToString2);
Rectangle startIndex = textArea.modelToView(pos2);
textArea.getHighlighter().addHighlight(pos2,
    pos2 + turnToString2.length(),
    new DefaultHighlighter.DefaultHighlightPainter(Color.yellow));

代码示例来源:origin: stackoverflow.com

Highlighter highlighter = tarea.getHighlighter();
highlighter.removeHighlight(highlights.get(startIndex));
tarea.setCaretPosition(startIndex);
Highlighter highlighter = tarea.getHighlighter();

代码示例来源:origin: apache/pdfbox

/**
 * 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;
}

代码示例来源:origin: apache/pdfbox

@Override
public void componentHidden(ComponentEvent componentEvent)
{
  textComponent.getHighlighter().removeAllHighlights();
}

代码示例来源:origin: apache/pdfbox

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();
  }
}

代码示例来源:origin: stackoverflow.com

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) {

代码示例来源:origin: stackoverflow.com

tarea.getHighlighter().addHighlight(startIndex, endIndex, painter);
tarea.getHighlighter().addHighlight(startIndex, endIndex, painter);
tarea.getHighlighter().addHighlight(startIndex, endIndex, painter);

代码示例来源:origin: apache/pdfbox

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();
  }
}

代码示例来源:origin: stackoverflow.com

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) {

代码示例来源:origin: stackoverflow.com

JTextComponent editor = //... your editor component;
SquiggleUnderlineHighlightPainter sqpainter = new SquiggleUnderlineHighlightPainter(Color.RED);
try {
  editor.getHighlighter().addHighlight(beginPosition, endPosition, sqpainter);
} 
catch (BadLocationException e) {
  e.printStackTrace();
}

代码示例来源:origin: com.fifesoft/autocomplete

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;
}

代码示例来源:origin: com.jidesoft/jide-oss

/**
 * 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();
  }
}

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: org.antlr/stringtemplate

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);
  }
}

代码示例来源:origin: RPTools/maptool

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);
    }
  }
}

代码示例来源:origin: nroduit/Weasis

public void removeHighlights(JTextComponent textComonent) {
  Highlighter hilite = textComonent.getHighlighter();
  for (Highlighter.Highlight highlight : hilite.getHighlights()) {
    if (highlight.getPainter() instanceof SearchHighlightPainter) {
      hilite.removeHighlight(highlight);
    }
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-bugtracking

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);
  }
}

代码示例来源:origin: org.gosu-lang.gosu/gosu-editor

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 );
  }
 }
}

代码示例来源:origin: com.bitplan.antlr/com.bitplan.antlr

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) {
 }
}

代码示例来源:origin: robo-code/robocode

/**
 * 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) {}
}

相关文章

JTextComponent类方法