如何调整屏幕以使光标指向在 java UI 中最大化/最小化或扩展窗口大小时突出显示的文本
问问题
44 次
1 回答
1
您应该查看java.awt.Robot
该类,该类可用于使用该mouseMove(int x, int y)
方法移动鼠标指针。
它是获取包含文本的组件的边界并将鼠标重新定位到边界中心的简单情况;例如
// Application frame definition:
JFrame frame = ...
// Text field embedded within frame:
JTextField txtFld = ...
// Add WindowListener responsible for detecting when window state changes.
frame.addWindowListener(new WindowAdapter() {
public void windowStateChanged(WindowEvent e) {
// Reposition mouse over text field providing window isn't iconified.
if (frame.getExtendedState() != JFrame.ICONIFIED) {
Rectangle bounds = txtFld.getBounds();
Robot.moveMouse(bounds.x / 2, bounds.y / 2);
}
}
});
于 2010-01-22T08:45:55.327 回答