JavaFX fxml“fx:id”属性的有效字符是什么?

时间:2016-01-28 04:33:27

标签: javafx javafx-8 fxml

这是在某处记录的吗?它是标准的XML指南吗?

我能够在SceneBuilder中指定fx:id =“table $ abc”,但“table> abc”给出了错误。

1 个答案:

答案 0 :(得分:3)

在FXMLLoader的源代码中,有一个方法processAttribute(...)" uumh" fx:idfx:controller等处理属性等。验证fx:id的代码是:

if ( localName.equals( FX_ID_ATTRIBUTE ) )
{
    // Verify that ID is a valid identifier
    if ( value.equals( NULL_KEYWORD ) )
    {
        throw constructLoadException( "Invalid identifier." );
    }

    for ( int i = 0, n = value.length(); i < n; i++ )
    {
        if ( !Character.isJavaIdentifierPart( value.charAt( i ) ) )
        {
            throw constructLoadException( "Invalid identifier." );
        }
    }

    fx_id = value;
}

因此,使用fx:id检查Character.isJavaIdentifierPart()中的每个字符。在

Character.isJavaIdentifierPart('$');  // returns true
Character.isJavaIdentifierPart('>');  // returns false

因此,使用>字符会抛出LoadException,而$却不会。{/ p>

可能没有有效的fx:id名称的文档,但至少阅读Character.isJavaIdentifierPart()的javadoc会给你一些见解。