如果我使用 Skin、Control 和 Behavior 类创建自定义控件,是否可以在 Java Scene Builder 中显示我的自定义属性?如果有人已经这样做了,你能解释一下怎么做吗?我在 Skin 和 Control 子类中都有属性,但没有成功。
谢谢
jack
编辑1:
因此其他人可以跟随,这里是场景生成器能够检测到的示例“Control”类。
public class DisplayControl extends Control
{ 私有(private)ObjectProperty m_BackgroundColor;
public DisplayControl()
{
m_Skin = new DisplaySkin(this);
m_BackgroundColor = new SimpleObjectProperty<>(new Color(0.5,
0.5,
0.5,
1));
setSkin(m_Skin);
}
public ObjectProperty<Color> backgroundColor()
{
return m_BackgroundColor;
}
/**
* @return the m_BackgroundColor
*/
public Color getBackgroundColor()
{
return m_BackgroundColor.get();
}
/**
* @param BackgroundColor the BackgroundColor to set
*/
public void setBackgroundColor(Color backgroundColor)
{
if (backgroundColor != m_BackgroundColor.get())
{
m_BackgroundColor.set(backgroundColor);
m_Skin.setBackgroundColor(backgroundColor);
}
}
}
最佳答案
使您的属性访问器方法遵循 standard naming pattern 。你应该有
public class DisplayControl extends Control {
// ...
public ObjectProperty<Color> backgroundColorProperty() { ... }
public Color getBackgroundColor() { ... }
public void setBackgroundColor(...) { ...}
}
关于java - 您能在带有自定义控件的 Java Scene Builder 中看到自定义属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26244590/