本文整理汇总了Java中javax.swing.text.DefaultCaret.setVisible方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultCaret.setVisible方法的具体用法?Java DefaultCaret.setVisible怎么用?Java DefaultCaret.setVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.DefaultCaret
的用法示例。
在下文中一共展示了DefaultCaret.setVisible方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.swing.text.DefaultCaret; //导入方法依赖的package包/类
public static void main(String[] args) {
DefaultCaret caret = new DefaultCaret();
for (int i = 0; i < 10; i++) {
boolean active = (i % 2 == 0);
caret.setVisible(active);
if (caret.isActive() != active) {
throw new RuntimeException("caret.isActive() does not equal: " + active);
}
}
}
示例2: ActiveClient
import javax.swing.text.DefaultCaret; //导入方法依赖的package包/类
ActiveClient() throws HeadlessException {
// prevent IM invocation on this component
enableInputMethods(false);
ComponentInternals ci = ComponentInternals.getComponentInternals();
TextKit textKit = ci.getTextKit(this);
caret = (DefaultCaret) textKit.getCaret();
caret.setBlinkRate(0);
caret.setVisible(true);
imRequests = new InputMethodRequestsImpl(textKit) {
@Override
public TextHitInfo getLocationOffset(int x, int y) {
if (!isShowing()) {
return null;
}
return super.getLocationOffset(x, y);
}
};
imListener = new InputMethodListenerImpl(textKit) {
@Override
public void inputMethodTextChanged(InputMethodEvent ime) {
super.inputMethodTextChanged(ime);
// create KEY_TYPED event for each committed char
// and send it to passive client or just
// redirect this event to active client
if (client == null) {
return;
}
InputMethodRequests imr = client.getInputMethodRequests();
if (imr != null) {
if (IMManager.belowTheSpot()) {
// position window below the spot:
TextHitInfo offset = TextHitInfo.leading(0);
Rectangle textLoc = imr.getTextLocation(offset);
setLocationBelow(textLoc);
} else {
client.dispatchEvent(ime);
return;
}
}
sendCommittedText(ime);
}
};
addInputMethodListener(imListener);
}