本文整理汇总了Java中java.awt.font.TextHitInfo.leading方法的典型用法代码示例。如果您正苦于以下问题:Java TextHitInfo.leading方法的具体用法?Java TextHitInfo.leading怎么用?Java TextHitInfo.leading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.font.TextHitInfo
的用法示例。
在下文中一共展示了TextHitInfo.leading方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLocationOffset
import java.awt.font.TextHitInfo; //导入方法依赖的package包/类
public TextHitInfo getLocationOffset(int x, int y) {
if (composedTextAttribute == null) {
return null;
} else {
Point p = getLocationOnScreen();
p.x = x - p.x;
p.y = y - p.y;
int pos = viewToModel(p);
if ((pos >= composedTextStart.getOffset()) &&
(pos <= composedTextEnd.getOffset())) {
return TextHitInfo.leading(pos - composedTextStart.getOffset());
} else {
return null;
}
}
}
示例2: x2Index
import java.awt.font.TextHitInfo; //导入方法依赖的package包/类
static TextHitInfo x2Index(TextLayout textLayout, float x) {
TextHitInfo hit;
hit = textLayout.hitTestChar(x, 0);
// Use forward bias only since BaseCaret and other code is not sensitive to backward bias yet
if (!hit.isLeadingEdge()) {
hit = TextHitInfo.leading(hit.getInsertionIndex());
}
return hit;
}
示例3: main
import java.awt.font.TextHitInfo; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
try {
Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
stubThread.start();
stubThread.join();
CountDownLatch startSwingLatch = new CountDownLatch(1);
new Thread(swingTG, () -> {
SunToolkit.createNewAppContext();
SwingUtilities.invokeLater(() -> {
frame = new JFrame();
component = new JLabel("Test Text");
frame.add(component);
frame.setBounds(100, 100, 100, 100);
frame.setVisible(true);
startSwingLatch.countDown();
});
}).start();
startSwingLatch.await();
AtomicReference<Exception> caughtException = new AtomicReference<>();
Thread checkThread = new Thread(getRootThreadGroup(), () -> {
try {
// If the bug is present this will throw exception
new InputMethodEvent(component,
InputMethodEvent.CARET_POSITION_CHANGED,
TextHitInfo.leading(0),
TextHitInfo.trailing(0));
} catch (Exception e) {
caughtException.set(e);
}
});
checkThread.start();
checkThread.join();
if (caughtException.get() != null) {
throw new RuntimeException("Failed. Caught exception!", caughtException.get());
}
} finally {
new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
if (frame != null) {
frame.dispose();
}
})).start();
}
}