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

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

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

JTextComponent.getSelectionStart介绍

暂无

代码示例

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

private boolean isExpectedNext(JTextComponent input, String nextChar)
  {
    String expected;
    if (input.getSelectionStart() < input.getSelectionEnd())
    {
      try
      {
        expected = input.getText(input.getSelectionStart(), 1);
      }
      catch (BadLocationException ex)
      {
        log.warn("Could not get first character from input selection.", ex);
        return false;
      }
    }
    else
    {
      expected = "";
    }
    return nextChar.equalsIgnoreCase(expected);
  }
}

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

private void newAutocomplete(KeyEvent e)
{
  final JTextComponent input = (JTextComponent)e.getSource();
  final String inputText = input.getText();
  final String nameStart = inputText.substring(0, input.getSelectionStart()) + e.getKeyChar();
  if (findAutocompleteName(nameStart))
  {
    // Assert this.autocompleteName != null
    final String name = this.autocompleteName;
    SwingUtilities.invokeLater(() ->
    {
      try
      {
        input.getDocument().insertString(
          nameStart.length(),
          name.substring(nameStart.length()),
          null);
        input.select(nameStart.length(), name.length());
      }
      catch (BadLocationException ex)
      {
        log.warn("Could not autocomplete name.", ex);
      }
    });
  }
}

代码示例来源:origin: groovy/groovy-core

textComponent.getSelectionStart();

代码示例来源:origin: groovy/groovy-core

textComponent.getSelectionStart();

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

final int insertIndex = input.getSelectionStart();
Document doc = input.getDocument();
doc.remove(insertIndex, 1);

代码示例来源:origin: groovy/groovy-core

public void actionPerformed(ActionEvent ae) {
    lastAction = FIND_ACTION_COMMAND;
    findReplaceCount = 0;
    if (FIND_REPLACE_DIALOG.isVisible() &&
        FIND_REPLACE_DIALOG.getTitle().equals(FIND_ACTION_COMMAND)) {
    }
    int pos = textComponent.getSelectedText() == null ?
        textComponent.getCaretPosition() :
        textComponent.getSelectionStart();
    boolean reverse = (ae.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
    pos = findNext(reverse, pos);
    if (pos > -1) {
      String pattern = (String) FIND_FIELD.getSelectedItem();
      textComponent.select(pos, pos + pattern.length());
      findReplaceCount = 1;
    }
    setListStrings();
    fireTextEvent();
  }
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Create a Transferable to use as the source for a data transfer.
 *
 * @param comp  The component holding the data to be transfered.  This
 *  argument is provided to enable sharing of TransferHandlers by
 *  multiple components.
 * @return  The representation of the data to be transfered.
 *
 */
@Override
protected Transferable createTransferable(JComponent comp) {
  exportComp = (JTextComponent)comp;
  shouldRemove = true;
  p0 = exportComp.getSelectionStart();
  p1 = exportComp.getSelectionEnd();
  return (p0 != p1) ? (new TextTransferable(exportComp, p0, p1)) : null;
}

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

ta.replaceRange("", ta.getSelectionStart(), ta.getSelectionEnd());

代码示例来源:origin: protegeproject/protege

private int getEffectiveCaretPosition(){
  int startSel = textComponent.getSelectionStart();
  if (startSel >= 0){
    return startSel;
  }
  return textComponent.getCaretPosition();
}

代码示例来源:origin: edu.stanford.protege/org.protege.editor.owl

private int getEffectiveCaretPosition(){
  int startSel = textComponent.getSelectionStart();
  if (startSel >= 0){
    return startSel;
  }
  return textComponent.getCaretPosition();
}

代码示例来源:origin: edu.stanford.protege/protege-editor-owl

private int getEffectiveCaretPosition(){
  int startSel = textComponent.getSelectionStart();
  if (startSel >= 0){
    return startSel;
  }
  return textComponent.getCaretPosition();
}

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

@Override
 public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
  JTextComponent jtc = (JTextComponent) popupMenu.getInvoker();
  boolean enableCutCopy = (jtc.getSelectionEnd() - jtc.getSelectionStart()) > 0;
  boolean enablePaste = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null) != null;
  mntmCut.setEnabled(enableCutCopy);
  mntmCopy.setEnabled(enableCutCopy);
  mntmPaste.setEnabled(enablePaste);
 }
});

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

/**
 * @return offset of replaced word
 */
public static int replaceWordAtCaret( JTextComponent editor, String strText )
{
 selectWordAtCaret( editor );
 int selectionStart = editor.getSelectionStart();
 editor.replaceSelection( strText == null ? "" : strText );
 return selectionStart;
}

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

@Override
  public void actionPerformed(JTextComponent target, SyntaxDocument sdoc,
      int dot, ActionEvent e) {
    try {
      int st = sdoc.getLineStartOffset(target.getSelectionStart());
      int en = sdoc.getLineEndOffset(target.getSelectionEnd());
      sdoc.remove(st, en - st);
    } catch (BadLocationException ex) {
      Logger.getLogger(DeleteLinesAction.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
}

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

@Override
  public void actionPerformed(JTextComponent target, SyntaxDocument sdoc,
      int dot, ActionEvent e) {
    try {
      int st = sdoc.getLineStartOffset(target.getSelectionStart());
      int en = sdoc.getLineEndOffset(target.getSelectionEnd());
      sdoc.remove(st, en - st);
    } catch (BadLocationException ex) {
      Logger.getLogger(DeleteLinesAction.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
}

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

@Override
public CompletionTask createTask(int queryType, JTextComponent component) {
  if (queryType != CompletionProvider.COMPLETION_QUERY_TYPE && queryType !=CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
    return null;
  }
  return new AsyncCompletionTask(new BeansCompletionQuery(queryType, component, component.getSelectionStart(), true), component);
}

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

public TextComponentTask(EditorCookie ec) {
  this.textC = ec.getOpenedPanes()[0];
  this.caret = textC.getCaretPosition();
  this.start = textC.getSelectionStart();
  this.end = textC.getSelectionEnd();
  assert caret != -1;
  assert start != -1;
  assert end != -1;
}

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

public void caretUpdate(CaretEvent e) {
  FileObject file = OpenedEditors.getFileObject(component);
  
  if (file != null) {
    setLastSelection(OpenedEditors.getFileObject(component), component.getSelectionStart(), component.getSelectionEnd());
    rescheduleTask.schedule(timeout);
  }
}

代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit

public void showPopupMenu(boolean search)
{
  if(search)
    showPopupMenu(getText().substring(getInputStart(),
      text.getSelectionStart()),0,text.getHeight());
  else
    showPopupMenu("",0,text.getHeight());
} //}}}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

public boolean isActive(DrawContext ctx, MarkFactory.DrawMark mark) {
  boolean active;
  if (mark != null) {
    active = mark.activateLayer;
  } else {
    JTextComponent c = ctx.getEditorUI().getComponent();
    active = (c != null) && c.getCaret().isSelectionVisible()
         && ctx.getFragmentOffset() >= c.getSelectionStart()
         && ctx.getFragmentOffset() < c.getSelectionEnd();
  }
  return active;
}

相关文章

JTextComponent类方法