java - JavaFX css tags -


i'm trying make list of boxes user can select through mouse , when 1 box selected, highlights color, , rest of boxes turn white. there equivalent css tag :target in javafx there equivalent :focus(:focused) or have handle selecting items in list own way?

there no built-in target pseudoclass, there api creating own css pseudoclass objects.

here simple example:

import javafx.application.application; import javafx.beans.property.objectproperty; import javafx.beans.property.simpleobjectproperty; import javafx.css.pseudoclass; import javafx.geometry.insets; import javafx.scene.scene; import javafx.scene.control.scrollpane; import javafx.scene.layout.pane; import javafx.scene.layout.vbox; import javafx.stage.stage;  public class selectableboxes extends application {      private static final pseudoclass selected_pseudoclass = pseudoclass.getpseudoclass("selected");      private objectproperty<pane> selectedbox = new simpleobjectproperty<>();       @override     public void start(stage primarystage) {         vbox container = new vbox(5);         container.setpadding(new insets(20));          int numboxes = 5 ;         (int = 0 ; < numboxes; i++) {             container.getchildren().add(createbox());         }         scrollpane scroller = new scrollpane(container);         scene scene = new scene(scroller, 400, 400);         scene.getstylesheets().add("selectable-boxes.css");         primarystage.setscene(scene);         primarystage.show();     }      private pane createbox() {         pane pane = new pane();         pane.setminsize(50, 50);         pane.getstyleclass().add("box");          pane.setonmouseclicked(e -> selectedbox.set(pane));          selectedbox.addlistener((obs, oldselection, newselection) ->              pane.pseudoclassstatechanged(selected_pseudoclass, newselection == pane));          return pane ;     }      public static void main(string[] args) {         launch(args);     } } 

with corresponding css file selectable-boxes.css:

.box {     -fx-border-width: 1 ;     -fx-border-color: black ; } .box:selected {     -fx-background-color: blue ; } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -