Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Windowlicker在OS X上不工作_Java_Macos_Swing - Fatal编程技术网

Java Windowlicker在OS X上不工作

Java Windowlicker在OS X上不工作,java,macos,swing,Java,Macos,Swing,我对OSX上的windowlicker有一个问题(在Windows上一切正常)。 问题是,当我尝试模拟用户对任何文本字段的输入时,数据没有正确插入(一些字母被切掉) 例如: JTextFieldDriver txField = new JTextFieldDriver(this, JTextField.class,

我对OSX上的windowlicker有一个问题(在Windows上一切正常)。 问题是,当我尝试模拟用户对任何文本字段的输入时,数据没有正确插入(一些字母被切掉)

例如:

JTextFieldDriver txField = new JTextFieldDriver(this, 
                                                JTextField.class, 
                                                named(fieldName));
txField.focusWithMouse();
txField.typeText(input);
System.setProperty("com.objogate.wl.keyboard", "Mac-GB");
前面的代码将导致我观察到windowlicker将输入插入名为fieldName的文本字段,并且输入将不完整(Peter将是Peer或Fred将是Fre等等)。在windows上一切都正常工作

我不确定这一切是否与警告有关。我在窗户上也有类似的感觉。警告是:
“警告:无法加载键盘布局Mac-,使用功能降低的回退布局(JAR条目com/objogate/wl/keyboard/Mac-在/Users/odo/.m2/repository/com/googlecode/windowlicker/windowlicker-core/r268/windowlicker-core-r268.JAR中找不到)”

windowlicker似乎不是很受欢迎的工具。尽管如此,我还是设法找出了根本原因。由于我没有使用英语语言环境,因此显示了无法设置键盘布局的警告。windowlicker似乎只支持Mac GB键盘布局。 如果设置了适当的系统属性,警告将消失。 例如:

JTextFieldDriver txField = new JTextFieldDriver(this, 
                                                JTextField.class, 
                                                named(fieldName));
txField.focusWithMouse();
txField.typeText(input);
System.setProperty("com.objogate.wl.keyboard", "Mac-GB");
然而,这并不能解决主要问题。经过几次试验后,我发现只有“a”和“d”字符被修剪。这是因为windowlicker插入它们时,就好像用户会按住“a”或“d”键一段时间一样。按住这些键会导致助手菜单调用,从而允许选择特殊字符。为了解决这个问题,我使用了JTextComponentDriver并找到了一个解决方法。解决方案是不使用驱动程序的typeText来插入文本。JTextComponentDriver的component()方法可用于检索实际的guy组件,然后可以调用实例setText()来设置文本

下面,我将介绍使用所述解决方案的助手类:

public class TextTyper {
    private final String inputText;

    privte TextTyper(String inputText) {
        this.inputText = inputText;
    }

    public static TextTyper typeText( final String inputText ){
        return new TextTyper( inputText );
    }

    public void into( JTextComponentDriver<?> driver ) throws Exception{
        driver.focusWithMouse();
        driver.clearText();

        Component cmp = driver.component().component();
        if(cmp instanceof JPasswordField ){
            JPasswordField pwField = (JPasswordField) cmp;
            pwField.setText(this.inputText);
        }
        else if( cmp instanceof JTextField){
            JTextField txField = (JTextField) cmp;
            txField.setText(this.inputText);
        }

        else
            throw new Exception("Component is not an instance of JTextField or JPasswordField");
    }
}
公共类文本打字机{
私有最终字符串inputText;
Private文本打字机(字符串输入文本){
this.inputText=inputText;
}
公共静态文本键入器键入文本(最终字符串输入文本){
返回新的文本打字机(inputText);
}
public void into(JTextComponentDriver)引发异常{
driver.focusWithMouse();
driver.clearText();
组件cmp=驱动程序.Component().Component();
if(JPasswordField的cmp实例){
JPasswordField pwField=(JPasswordField)cmp;
pwField.setText(this.inputText);
}
else if(JTextField的cmp实例){
JTextField txField=(JTextField)cmp;
txField.setText(this.inputText);
}
其他的
抛出新异常(“组件不是JTextField或JPasswordField的实例”);
}
}