java - Apply skin to all JavaFX child controls -


i implementing javafx controls 2 custom skins. have basic controls, each of them has 2 different skins, , control groups 2 of these together. wondering how can implement skin of composite control when want skin 2 embedded controls in same way, i.e. there should 2 skins composite controls, , when apply 1 of the embedded controls should skinned. basically, want have skin applied recursively on control graph.

class control1 extends control {} class control1skin1 extends skinbase<control1> {} class control1skin2 extends skinbase<control1> {}  class control2 extends control {} class control2skin1 extends skinbase<control1> {} class control2skin2 extends skinbase<control1> {}  class compositecontrol extend control {     private final control1 ctrl1 = new control1();     private final control2 ctrl2 = new control2(); }  class compositecontrolskin1 extends skinbase<control1> {} class compositecontrolskin2 extends skinbase<control1> {} 
  1. make controls members of skin. leads code duplication , moves logic skin doesn't belong there.
  2. add accessors compositecontrol access embedded controls. breaks encapsulation.
  3. make members package private such skin can access them , set skin appropriately. minor breach in encapsulation, skin , control class form cohesive cluster anyway.
  4. define custom compositecontrolskin interface has methods returning skins sub-controls. then, have override compositecontrol.setskin(skin skin)to cast theskin` parameter new interface, skins , set them. needs access members in 3, additionally down-cast. think disqualifies approach.

i wondering if there better approach in javafx, e.g. composite skin. documentation custom skinnable controls found bit sparse, grateful links or hints.

first, make sure need additional skins. skins needed if want controls , behave different default. usually, styling application css enough.

if come conclusion need additional skins, check following steps:

  1. every skinnable custom control should have specific style class

:

private static final string default_style_class = "my-control";      [...]      public mycontrol(){         getstyleclass().setall(default_style_class);     } 
  1. identify controls, need additional skin. might not true of controls (e.g. additional skins composite controls might not necessary)

  2. override skins want use in custom css:

:

.my-control {      -fx-skin: "somepackage.skin.mycontrolskin2"; } 

please note, need extend control , provide skin if want highly customizable , highly-reusable control.

for application developers, of time can create reusable controls using fx:root fxml construct. e.g. composite controls might candidates this.

custom skinnable controls don't consist of other controls ties control specific , feel. if want skinnable composite controls, nested controls should in skin, not in control.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -