Javafx Not Editable Combobox prompt text style with CSS -


i'm trying have not editable combobox having prompt text fill text color bit lighter actual text fill color (as text input).

i crossed topic explains solution going through override of button cell: javafx 8 - how change color of prompt text of not editable combobox via css?

my question pretty simple: can implement mechanism described in post through css file? have feeling not possible, i'm not expert @ in css wonder if may have missed something.

a skin can assigned css. apply modifications skinnable in skin's constructor, not skins should do.

assigning pseudoclass whenever no item selected skin do.

with such pseudo-class buttoncell can styled css.

package combobox.promptstyle;  import com.sun.javafx.scene.control.skin.comboboxlistviewskin; import javafx.beans.value.changelistener; import javafx.css.pseudoclass; import javafx.scene.control.combobox; import javafx.scene.control.selectionmodel;  // extend default combobox skin public class promptskin<t> extends comboboxlistviewskin<t> {      private static final pseudoclass prompt = pseudoclass.getpseudoclass("prompt");      public promptskin(final combobox<t> combobox) {         super(combobox);          changelistener<number> selectionindexchangelistener = (observable, oldindex, newindex) -> {             getnode().pseudoclassstatechanged(prompt, newindex.intvalue() < 0);         };          changelistener<selectionmodel> modelchangelistener = (observable, oldselectionmodel, newselectionmodel) -> {             if (oldselectionmodel != null) {                 oldselectionmodel.selectedindexproperty().removelistener(selectionindexchangelistener);             }              if (newselectionmodel != null) {                 newselectionmodel.selectedindexproperty().addlistener(selectionindexchangelistener);                 selectionindexchangelistener.changed(null, null, newselectionmodel.getselectedindex());             } else {                 selectionindexchangelistener.changed(null, null, -1);             }         };          combobox.selectionmodelproperty().addlistener(modelchangelistener);         modelchangelistener.changed(null, null, combobox.getselectionmodel());     }  } 

example using skin:

combobox combobox = ... combobox.setid("combo");  // set stylesheet 

css stylesheet

#combo {     /* set skin use */     -fx-skin: 'combobox.promptstyle.promptskin'; }  #combo:prompt > .list-cell {     -fx-text-fill: derive(-fx-control-inner-background,-30%); } 

note skin extends class com.sun packages, may subject change.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -