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


Java Caret.setMagicCaretPosition方法代码示例

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


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

示例1: resetCaretMagicPosition

import javax.swing.text.Caret; //导入方法依赖的package包/类
public static void resetCaretMagicPosition(JTextComponent component) {
    Caret caret;
    if (component != null && (caret = component.getCaret()) != null) {
        caret.setMagicCaretPosition(null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:EditorActionUtilities.java

示例2: actionPerformedImpl

import javax.swing.text.Caret; //导入方法依赖的package包/类
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {

	Rectangle visible = textArea.getVisibleRect();
	Rectangle newVis = new Rectangle(visible);
	int selectedIndex = textArea.getCaretPosition();
	int scrollAmount = textArea.getScrollableBlockIncrement(
					visible, SwingConstants.VERTICAL, direction);
	int initialY = visible.y;
	Caret caret = textArea.getCaret();
	Point magicPosition = caret.getMagicCaretPosition();
	int yOffset;

	if (selectedIndex!=-1) {

		try {

			Rectangle dotBounds = textArea.modelToView(selectedIndex);
			int x = (magicPosition != null) ? magicPosition.x :
										dotBounds.x;
			int h = dotBounds.height;
			yOffset = direction *
					((int)Math.ceil(scrollAmount/(double)h)-1)*h;
			newVis.y = constrainY(textArea, initialY+yOffset, yOffset, visible.height);
			int newIndex;

			if (visible.contains(dotBounds.x, dotBounds.y)) {
				// Dot is currently visible, base the new
				// location off the old, or
				newIndex = textArea.viewToModel(
							new Point(x, constrainY(textArea,
								dotBounds.y + yOffset, 0, 0)));
								}
			else {
				// Dot isn't visible, choose the top or the bottom
				// for the new location.
				if (direction == -1) {
					newIndex = textArea.viewToModel(new Point(
											x, newVis.y));
				}
				else {
					newIndex = textArea.viewToModel(new Point(
							x, newVis.y + visible.height));
				}
			}
			newIndex = constrainOffset(textArea, newIndex);
			if (newIndex != selectedIndex) {
				// Make sure the new visible location contains
				// the location of dot, otherwise Caret will
				// cause an additional scroll.
				adjustScrollIfNecessary(textArea, newVis, initialY,
									newIndex);
				if (select) {
					textArea.moveCaretPosition(newIndex);
				}
				else {
					textArea.setCaretPosition(newIndex);
				}
			}

		} catch (BadLocationException ble) { }

	} // End of if (selectedIndex!=-1).

	else {
		yOffset = direction * scrollAmount;
		newVis.y = constrainY(textArea, initialY + yOffset, yOffset, visible.height);
	}

	if (magicPosition != null) {
		caret.setMagicCaretPosition(magicPosition);
	}

	textArea.scrollRectToVisible(newVis);
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:76,代码来源:RTextAreaEditorKit.java


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