我需要实现任何输入法接口以使ime候选窗口显示在光标位置吗? Windows默认ime似乎显示在正确的位置,而不是google ime和RedHat ime。这是一些示例代码:
import javax.swing.JFrame;
import javax.swing.JTextField;
class ime
{
public static void main(String args[])
{
JFrame f = new JFrame("TextField Example");
JTextField t1, t2;
t1 = new JTextField("Welcome to Javatpoint.");
t1.setBounds(50, 100, 200, 30);
t2 = new JTextField("AWT Tutorial");
t2.setBounds(50, 150, 200, 30);
f.add(t1);
f.add(t2);
f.setSize(400, 400);
f.setLayout(null);
f.setVisible(true);
}
}
截屏:
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS8wdmNNMy5wbmcifQ==” alt =“ Google ime定位不正确”>
下面的内容实际上是评论,而不是答案,但是我不能像评论一样格式化评论。
这是我在Swing希伯来语(从右到左书写)的GUI中的处理方式
java.awt.im.InputContext ic = t1.getInputContext(); // 't1' is the JTextField from the code you posted.
ic.selectInputMethod(new java.util.Locale("iw", "IL");
iw是希伯来语的语言代码。IL是以色列的国家代码
这不是完整的答案,而是提示您如何进行:SwingUtilities类具有将组件坐标转换为屏幕坐标的几种方法。
您需要在屏幕上获得组件的位置,并在该位置显示一个小窗口,您可以根据自己的喜好以较小的偏移量显示。