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

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

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

JTextComponent.addCaretListener介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

/**
 *  Create a line number component for a text component.
 *
 *  @param component  the related text component
 *  @param minimumDisplayDigits  the number of digits used to calculate
 *                               the minimum width of the component
 */
public TextLineNumber(JTextComponent component, int minimumDisplayDigits) {
 this.component = component;
 setFont(component.getFont());
 setBorderGap(5);
 setCurrentLineForeground(Color.RED);
 setDigitAlignment(RIGHT);
 setMinimumDisplayDigits(minimumDisplayDigits);
 component.getDocument().addDocumentListener(this);
 component.addCaretListener(this);
 component.addPropertyChangeListener("font", this);
}

代码示例来源:origin: de.sciss/jsyntaxpane

@Override
public void install(JEditorPane editor) {
  pane = editor;
  pane.addCaretListener(this);
  status = Status.INSTALLING;
}

代码示例来源:origin: de.sciss/syntaxpane

@Override
public void install(JEditorPane editor) {
  pane = editor;
  pane.addCaretListener(this);
  status = Status.INSTALLING;
}

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

public void addTo(JTextComponent tc) {
  tc.addFocusListener(this);
  tc.getDocument().addDocumentListener(this);
  tc.addCaretListener(this);
}

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

public void establishUndoableEditListener( JTextComponent editor )
{
 editor.getDocument().addUndoableEditListener( this );
 editor.addCaretListener( this );
 _editor = editor;
}

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

public void establishUndoableEditListener( JTextComponent editor )
{
 editor.getDocument().addUndoableEditListener( this );
 editor.addCaretListener( this );
 _editor = editor;
}

代码示例来源:origin: de.sciss/jsyntaxpane

public CaretMonitor(JTextComponent text, JLabel label) {
  this.label = label;
  this.text = text;
  text.addCaretListener(this);
  updateLabel(text.getCaretPosition());
}

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

/** Creates a new instance of ComponentPeer */
  private ComponentPeer(JTextComponent pane) {
    this.pane = pane;
//        reschedule();
    pane.addPropertyChangeListener(this);
    pane.addCaretListener(this);
    pane.addAncestorListener(this);
    document = pane.getDocument();
    document.addDocumentListener(this);

    ancestorAdded(null);
  }

代码示例来源:origin: de.sciss/syntaxpane

@Override
  public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals("document")) {
        pane.removeCaretListener(this);
      if (status.equals(Status.INSTALLING)) {
        pane.addCaretListener(this);
        removeMarkers();
      }
    }
  }    
}

代码示例来源:origin: de.sciss/syntaxpane

public CaretMonitor(JTextComponent text, JLabel label) {
  this.label = label;
  this.text = text;
  text.addCaretListener(this);
  updateLabel(text.getCaretPosition());
}

代码示例来源:origin: de.sciss/jsyntaxpane

@Override
  public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals("document")) {
        pane.removeCaretListener(this);
      if (status.equals(Status.INSTALLING)) {
        pane.addCaretListener(this);
        removeMarkers();
      }
    }
  }    
}

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

public void stateChanged(ChangeEvent e) {
  List<JTextComponent> added = new ArrayList<JTextComponent>(OpenedEditors.getDefault().getVisibleEditors());
  List<JTextComponent> removed = new ArrayList<JTextComponent>(component2Listener.keySet());
  
  added.removeAll(component2Listener.keySet());
  removed.removeAll(OpenedEditors.getDefault().getVisibleEditors());
  
  for (JTextComponent c : removed) {
    c.removeCaretListener(component2Listener.remove(c));
  }
  
  for (JTextComponent c : added) {
    ComponentListener l = new ComponentListener(c);
    
    c.addCaretListener(l);
    component2Listener.put(c, l);
    
    //TODO: are we in AWT Thread?:
    setLastSelection(OpenedEditors.getFileObject(c), c.getSelectionStart(), c.getSelectionEnd());
  }
  
  fileObjectsChanged();
}

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

public void stateChanged(ChangeEvent e) {
  List<JTextComponent> added = new ArrayList<JTextComponent>(OpenedEditors.getDefault().getVisibleEditors());
  List<JTextComponent> removed = new ArrayList<JTextComponent>(component2Listener.keySet());
  
  added.removeAll(component2Listener.keySet());
  removed.removeAll(OpenedEditors.getDefault().getVisibleEditors());
  
  for (JTextComponent c : removed) {
    c.removeCaretListener(component2Listener.remove(c));
  }
  
  for (JTextComponent c : added) {
    ComponentListener l = new ComponentListener(c);
    
    c.addCaretListener(l);
    component2Listener.put(c, l);
    
    //TODO: are we in AWT Thread?:
    setLastPosition(OpenedEditors.getFileObject(c), c.getCaretPosition());
  }
  
  fileObjectsChanged();
}

代码示例来源:origin: de.sciss/jsyntaxpane

/**
 * Creates new form FindDialog
 * @param text
 * @param dsd DocumentSerachData
 */
public ReplaceDialog(JTextComponent text,
  DocumentSearchData dsd) {
  super(SwingUtilities.getWindowAncestor(text), ModalityType.MODELESS.MODELESS);
  initComponents();
  textComponent = text;
  this.dsd = dsd;
  textComponent.addCaretListener(this);
  setLocationRelativeTo(text.getRootPane());
  getRootPane().setDefaultButton(jBtnNext);
  SwingUtils.addEscapeListener(this);
  jBtnReplaceAll.setEnabled(text.isEditable() && text.isEnabled());
}

代码示例来源:origin: org.xworker/xworker_core

public static void createCaretListeners(ActionContext actionContext){
  Thing self = (Thing) actionContext.get("self");
  JTextComponent parent = (JTextComponent) actionContext.get("parent");
  
  for(Thing child : self.getChilds()){
    CaretListener l = (CaretListener) child.doAction("create", actionContext);
    if(l != null){
      parent.addCaretListener(l);
    }
  }
}

代码示例来源:origin: de.sciss/syntaxpane

/**
 * Creates new form FindDialog
 * @param text
 * @param dsd DocumentSerachData
 */
public ReplaceDialog(JTextComponent text,
  DocumentSearchData dsd) {
  super(SwingUtilities.getWindowAncestor(text), ModalityType.MODELESS.MODELESS);
  initComponents();
  textComponent = text;
  this.dsd = dsd;
  textComponent.addCaretListener(this);
  setLocationRelativeTo(text.getRootPane());
  getRootPane().setDefaultButton(jBtnNext);
  SwingUtils.addEscapeListener(this);
  jBtnReplaceAll.setEnabled(text.isEditable() && text.isEnabled());
}

代码示例来源:origin: mucommander/mucommander

public TextLineNumbersPanel(JTextComponent component, int minimumDisplayDigits, Border border, int borderGap, 
    ALIGNMENT alignment) {
  this.component = component;
  setBackground(Color.LIGHT_GRAY);
  setForeground(Color.black);
  setCurrentLineForeground(new Color(0,0,255));
  setDigitAlignment(alignment);
  setBorder(border, borderGap);
  setMinimumDisplayDigits( minimumDisplayDigits);
  setFont(component.getFont());
  
  component.getDocument().addDocumentListener(this);
  component.addPropertyChangeListener("font", this);
  component.addCaretListener(this);
}

代码示例来源: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) {}
}

代码示例来源:origin: org.jdesktop.bsaf/bsaf

void updateFocusOwner(JComponent oldOwner, JComponent newOwner) {
  if (oldOwner instanceof JTextComponent) {
    JTextComponent text = (JTextComponent) oldOwner;
    text.removeCaretListener(textComponentCaretListener);
    text.removePropertyChangeListener(textComponentPCL);
  }
  if (newOwner instanceof JTextComponent) {
    JTextComponent text = (JTextComponent) newOwner;
    maybeInstallTextActions(text);
    updateTextActions(text);
    text.addCaretListener(textComponentCaretListener);
    text.addPropertyChangeListener(textComponentPCL);
  } else if (newOwner == null) {
    setCopyEnabled(false);
    setCutEnabled(false);
    setPasteEnabled(false);
    setDeleteEnabled(false);
    setSelectAllEnabled(false);
  }
}

相关文章

JTextComponent类方法