2014-10-07 54 views
2

如果我使用Skin,Control和Behavior类创建自定义控件,是否可以在Java Scene Builder中显示我的自定义属性?如果有人已经这样做了,你能解释一下吗?我在Skin和Control子类中都有属性,但没有成功。您是否可以在具有自定义控件的Java Scene Builder中看到自定义属性?

感谢

JEC

编辑1:

,以便其他人可以按照沿,这里是一个样本 '控制' 类场景生成器能够检测。

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); 
    } 
} 

}

+0

好吧,我想我有这部分想通了。所以你需要在'Control'类中拥有这个属性。确保'Control'类的jar已构建,然后导入到Scene Builder中。然后,在放置“控制”后,属性将在“属性”窗口的“自定义”下列出。在我的情况下,它的颜色和字段仍然是不可编辑的,所以我仍在处理这个问题。 – jecjackal 2014-10-07 22:54:34

回答

1

让你的属性访问方法遵循standard naming pattern。你应该有

public class DisplayControl extends Control { 

// ... 

    public ObjectProperty<Color> backgroundColorProperty() { ... } 
    public Color getBackgroundColor() { ... } 
    public void setBackgroundColor(...) { ...} 
} 
+0

工作。我仍然无法直接在SceneBuilder中编辑颜色,但至少在那里。谢谢 – jecjackal 2014-10-09 11:05:51

1

如果你使用javafx.scene.paint.Paint而不是颜色的,该值将是编辑在场景生成器

public class DisplayControl extends Control { 

    // ... 

    public ObjectProperty<Paint> backgroundColorProperty() { ... } 
    public final Paint getBackgroundColor() { ... } 
    public final void setBackgroundColor(final Paint color) { ...} 
} 
相关问题