当前位置: 首页>>代码示例>>Java>>正文


Java JTextComponent.setCaretPosition方法代码示例

本文整理汇总了Java中javax.swing.text.JTextComponent.setCaretPosition方法的典型用法代码示例。如果您正苦于以下问题:Java JTextComponent.setCaretPosition方法的具体用法?Java JTextComponent.setCaretPosition怎么用?Java JTextComponent.setCaretPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.JTextComponent的用法示例。


在下文中一共展示了JTextComponent.setCaretPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setFieldData

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void setFieldData(String[] textLines) {
    clearFieldData();

    for (String line : textLines) {
        String[] values = line.split("::");

        if (values.length == 2) {
            GridItem gridItem = componentMap.get(values[0]);

            if (gridItem.isExportable && gridItem.component instanceof JTextComponent) {
                JTextComponent field = ((JTextComponent) gridItem.component);
                field.setText(values[1]);
                field.setCaretPosition(0);
            }
        }
    }
}
 
开发者ID:jgmeyerucsd,项目名称:PIQEDia,代码行数:18,代码来源:GetInput.java

示例2: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/** The operation to perform when this action is triggered. */
public void actionPerformed(ActionEvent e) {
    JTextComponent target = getTextComponent(e);
    if (target != null) {
        Document doc = target.getDocument();
        Element map = doc.getDefaultRootElement();
        int offs = target.getCaretPosition();
        int lineIndex = map.getElementIndex(offs);
        int lineEnd = map.getElement(lineIndex).getEndOffset() - 1;

        if (select) {
            target.moveCaretPosition(lineEnd);
        } else {
            target.setCaretPosition(lineEnd);
        }
    }            
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:OutputEditorKit.java

示例3: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target == null || target.getDocument() == null) {
        return;
    }
    Document doc = target.getDocument();
    AtomicLockDocument ald = LineDocumentUtils.asRequired(doc, AtomicLockDocument.class);
    
    ShellSession s = ShellSession.get(doc);
    if (s == null) {
        return;
    }
    ConsoleModel mod = s.getModel();
    ConsoleSection sec = mod.processInputSection(true);
    if (sec == null || sec.isIncomplete()) {
        return;
    }
    flushUndoQueue(doc);
    try {
        s.evaluate(null);
        target.setCaretPosition(doc.getLength());
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:OverrideEditorActions.java

示例4: setPlainText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void setPlainText(JTextComponent field, String value, boolean loading) {
    if (value == null) {
        if (loading) {
            field.setText(LBL_Loading());
        } else {
            field.setText(LBL_Undefined());
        }
    } else {
        field.setText(value);
        field.setCaretPosition(0);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ProjectInfoPanel.java

示例5: moveToNextParam

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Moves to and selects the next parameter.
 *
 * @see #moveToPreviousParam()
 */
private void moveToNextParam() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getCaretPosition();
	int tagCount = tags.size();
	if (tagCount==0) {
		tc.setCaretPosition(maxPos.getOffset());
		deactivate();
	}

	Highlight currentNext = null;
	int pos = -1;
	List<Highlight> highlights = getParameterHighlights();
	for (int i=0; i<highlights.size(); i++) {
		Highlight hl = highlights.get(i);
		// Check "< dot", not "<= dot" as OutlineHighlightPainter paints
		// starting at one char AFTER the highlight starts, to work around
		// Java issue.  Thanks to Matthew Adereth!
		if (currentNext==null || currentNext.getStartOffset()</*=*/dot ||
				(hl.getStartOffset()>dot &&
				hl.getStartOffset()<=currentNext.getStartOffset())) {
			currentNext = hl;
			pos = i;
		}
	}

	// No params after caret - go to first one
	if (currentNext.getStartOffset()+1<=dot) {
		int nextIndex = getFirstHighlight(highlights);
		currentNext = highlights.get(nextIndex);
		pos = 0;
	}

	// "+1" is a workaround for Java Highlight issues.
	tc.setSelectionStart(currentNext.getStartOffset()+1);
	tc.setSelectionEnd(currentNext.getEndOffset());
	updateToolTipText(pos);

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:45,代码来源:ParameterizedCompletionContext.java

示例6: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        try {
            Caret caret = target.getCaret();
            boolean emptySelection = false;
            boolean disableNoSelectionCopy =
                    Boolean.getBoolean("org.netbeans.editor.disable.no.selection.copy");
            int caretPosition = caret.getDot();
            if(!disableNoSelectionCopy &&
                    (!(caret instanceof EditorCaret)) || !(((EditorCaret)caret).getCarets().size() > 1)) {
                emptySelection = !Utilities.isSelectionShowing(target);
                // If there is no selection then pre-select a current line including newline
                if (emptySelection && !disableNoSelectionCopy) {
                    Element elem = ((AbstractDocument) target.getDocument()).getParagraphElement(
                            caretPosition);
                    if (!Utilities.isRowWhite((BaseDocument) target.getDocument(), elem.getStartOffset())) {
                        target.select(elem.getStartOffset(), elem.getEndOffset());
                    }
                }
            }
            target.copy();
            if (emptySelection && !disableNoSelectionCopy) {
                target.setCaretPosition(caretPosition);
            }
        } catch (BadLocationException ble) {
            LOG.log(Level.FINE, null, ble);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:BaseKit.java

示例7: navigateToOccurence

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private static void navigateToOccurence(boolean next, JTextComponent txt) {
    if (txt != null && txt.getDocument() != null) {
        Document doc = txt.getDocument();
        int position = txt.getCaretPosition();
        int goTo = findOccurrencePosition(next, doc, position);
        if (goTo > 0) {
            txt.setCaretPosition(goTo);
        } else {
            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(GoToMarkOccurrencesAction.class, "csl-no-marked-occurrence"));
        }
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:GoToMarkOccurrencesAction.java

示例8: mouseClicked

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public void mouseClicked(final MouseEvent e) {
    if (e.getClickCount() != 1) return;

    final JTextComponent c = getComponent();
    // apparently, focus has already been granted by the time this mouse listener fires
//    if (c.hasFocus()) return;

    c.setCaretPosition(viewToModel(c, e.getPoint()));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:AquaTextFieldFormattedUI.java

示例9: completeAsUser

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private static void completeAsUser(JTextComponent comp, String what, int where) {
    Document doc = comp.getDocument();
    try {
        int end = comp.getSelectionEnd();
        int len = end - where;
        if (len > 0) {
            doc.remove(where, len);
        }
        doc.insertString(where, what, null);
        comp.setCaretPosition(where + what.length());
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:JavadocCompletionItem.java

示例10: navigateToOccurence

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private static void navigateToOccurence(boolean next, JTextComponent txt) {
    if (txt != null && txt.getDocument() != null) {
        Document doc = txt.getDocument();
        int position = txt.getCaretPosition();
        int goTo = findOccurrencePosition(next, doc, position);
        if (goTo > 0) {
            txt.setCaretPosition(goTo);
            doc.putProperty(markedOccurence, new long[] {DocumentUtilities.getDocumentVersion(doc), goTo});
        } else {
            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(GoToMarkOccurrencesAction.class, "java-no-marked-occurrence"));
            doc.putProperty(markedOccurence, null);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:GoToMarkOccurrencesAction.java

示例11: performGoto

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Perform the goto operation.
 *
 * @return whether the dialog should be made invisible or not
 */
private boolean performGoto() {
    JTextComponent c = getTargetComponent();
    String text = (String) gotoCombo.getEditor().getItem();
    if (c != null) {
        try {
            int lineNumber = Integer.parseInt(text);
            if (lineNumber == 0) { // Works in vim to jump to begining
                lineNumber = 1;
            }
            int lineIndex = lineNumber - 1;
            Document doc = c.getDocument();
            Element rootElem = doc.getDefaultRootElement();
            int lineCount = rootElem.getElementCount();
            if (lineIndex >= 0) {
                if (lineIndex >= lineCount) {
                    lineIndex = lineCount - 1;
                }
                int offset = rootElem.getElement(lineIndex).getStartOffset();
                c.setCaretPosition(offset);
                return true;
            } // else: lineIndex < 0 => beep and return false
        } catch (NumberFormatException e) {
            // Contains letters or other chars -> attempt bookmarks
            BookmarkManager lockedBookmarkManager = BookmarkManager.getLocked();
            try {
                BookmarkInfo bookmark = lockedBookmarkManager.findBookmarkByNameOrKey(text, false);
                if (bookmark != null) {
                    BookmarkUtils.postOpenEditor(bookmark);
                    return true;
                } // else: unknown bookmark => beep
            } finally {
                lockedBookmarkManager.unlock();
            }
        }
    }
    c.getToolkit().beep();
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:GotoLineOrBookmarkPanel.java

示例12: replaceText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
boolean replaceText( JTextComponent component, String text, int offset, int len) {
    boolean replaced = super.replaceText(component, text, offset, len);
    if(replaced) {
        //shift the cursor between tags
        component.setCaretPosition(offset);
    }
    return replaced;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:EndTagAutocompletionResultItem.java

示例13: mouseClicked

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void mouseClicked(final MouseEvent e) {
    if (e.getClickCount() != 1) return;

    final JTextComponent c = getComponent();
    // apparently, focus has already been granted by the time this mouse listener fires
//    if (c.hasFocus()) return;

    c.setCaretPosition(viewToModel(c, e.getPoint()));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:AquaTextFieldFormattedUI.java

示例14: setText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Set the <code>text</code> for the <code>textComp</code> and set its
 * caret position to the end of the text.
 */
public static void setText(JTextComponent textComp, String text) {
    textComp.setText(text);
    textComp.setCaretPosition(text == null ? 0 : text.length());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ApisupportAntUIUtils.java

示例15: updateFieldsFromState

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void updateFieldsFromState() {
  isUpdating = true;
  properties.clear();

  final SequenceEncoder.Decoder defDecoder =
    new SequenceEncoder.Decoder(m_definition, DEF_DELIMITOR);
  final SequenceEncoder.Decoder stateDecoder =
    new SequenceEncoder.Decoder(state, STATE_DELIMITOR);

  for (int iField = 0; defDecoder.hasMoreTokens(); ++iField) {
    String name = defDecoder.nextToken();
    if (name.length() == 0) {
      continue;
    }

    final int type = name.charAt(0) - '0';
    name = name.substring(1);
    String value = stateDecoder.nextToken("");
    switch (type) {
    case TICKS:
    case TICKS_VAL:
    case TICKS_MAX:
    case TICKS_VALMAX:
      final int index = value.indexOf('/');
      properties.put(name, index > 0 ? value.substring(0, index) : value);
      break;
    default:
      properties.put(name, value);
    }

    value = value.replace(LINE_DELIMINATOR, '\n');

    if (frame != null) {
      final Object field = m_fields.get(iField);
      if (field instanceof JTextComponent) {
        final JTextComponent tf = (JTextComponent) field;
        final int pos = Math.min(tf.getCaretPosition(), value.length());
        tf.setText(value);
        tf.setCaretPosition(pos);
      }
      else if (field instanceof TickPanel) {
        ((TickPanel) field).updateValue(value);
      }
    }
  }

  if (applyButton != null) {
    applyButton.setEnabled(false);
  }

  isUpdating = false;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:53,代码来源:PropertySheet.java


注:本文中的javax.swing.text.JTextComponent.setCaretPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。