Typesafe stylesheet for tableviews cell depending on conditionKotlin Ternary Conditional OperatorTornadofx tableview sync two tablestornadofx EventBus expand table row using tableview objectTornadofx tableview using comboBox & adding FXEvent on buttonsTornadoFX JavaFX Sync Scroll across tableviewsCellCache renders unexpectedly in TableView with tornadoFXTornadofx - controlling tableview row object while buildSmooth scrolling in JavaFX TableViewHow to add a combobox to a tableview in Kotlin using TornadoFxAccess css color-variables in a typesafe stylesheet

How do I rename a Linux host without needing to reboot for the rename to take effect?

Increase performance creating Mandelbrot set in python

Large drywall patch supports

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

How easy is it to start Magic from scratch?

Return the Closest Prime Number

What happens if you roll doubles 3 times then land on "Go to jail?"

System.debug(JSON.Serialize(o)) Not longer shows full string

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

Integer addition + constant, is it a group?

Do the temporary hit points from the Battlerager barbarian's Reckless Abandon stack if I make multiple attacks on my turn?

How do I extract a value from a time formatted value in excel?

How does buying out courses with grant money work?

Was Spock the First Vulcan in Starfleet?

How to run a prison with the smallest amount of guards?

Why are there no referendums in the US?

Failed to fetch jessie backports repository

Why not increase contact surface when reentering the atmosphere?

What is the difference between "behavior" and "behaviour"?

How long to clear the 'suck zone' of a turbofan after start is initiated?

How can a function with a hole (removable discontinuity) equal a function with no hole?

Where does the Z80 processor start executing from?

Avoiding estate tax by giving multiple gifts

Class Action - which options I have?



Typesafe stylesheet for tableviews cell depending on condition


Kotlin Ternary Conditional OperatorTornadofx tableview sync two tablestornadofx EventBus expand table row using tableview objectTornadofx tableview using comboBox & adding FXEvent on buttonsTornadoFX JavaFX Sync Scroll across tableviewsCellCache renders unexpectedly in TableView with tornadoFXTornadofx - controlling tableview row object while buildSmooth scrolling in JavaFX TableViewHow to add a combobox to a tableview in Kotlin using TornadoFxAccess css color-variables in a typesafe stylesheet













1















I have the following code to define a tableview with specific cells changing color depending on condition.



How I can define a typesafe stylesheet class and apply it to current code preventing the duplication in future?



class MonitorView : View("Monitor") 
override val root = borderpane
center = tableview<ServerModel>
items = readConfiguration().observable()
readonlyColumn("Environment", ServerModel::env)
readonlyColumn("Host", ServerModel::host)
readonlyColumn("Port", ServerModel::port)
readonlyColumn("Application Name", ServerModel::appName)
column("Is online", ServerModel::isReachable).cellFormat
styleDependingOnBoolean(it)
graphic = hbox
button("Restart").action
isDisable = true






private fun TableCell<ServerModel, Boolean>.styleDependingOnBoolean(it: Boolean)
if (it)
style = "-fx-background-color:#00b200; -fx-text-fill:white"
text = it.toString()
else
style = "-fx-background-color:#8b0000; -fx-text-fill:white"
text = it.toString()













share|improve this question


























    1















    I have the following code to define a tableview with specific cells changing color depending on condition.



    How I can define a typesafe stylesheet class and apply it to current code preventing the duplication in future?



    class MonitorView : View("Monitor") 
    override val root = borderpane
    center = tableview<ServerModel>
    items = readConfiguration().observable()
    readonlyColumn("Environment", ServerModel::env)
    readonlyColumn("Host", ServerModel::host)
    readonlyColumn("Port", ServerModel::port)
    readonlyColumn("Application Name", ServerModel::appName)
    column("Is online", ServerModel::isReachable).cellFormat
    styleDependingOnBoolean(it)
    graphic = hbox
    button("Restart").action
    isDisable = true






    private fun TableCell<ServerModel, Boolean>.styleDependingOnBoolean(it: Boolean)
    if (it)
    style = "-fx-background-color:#00b200; -fx-text-fill:white"
    text = it.toString()
    else
    style = "-fx-background-color:#8b0000; -fx-text-fill:white"
    text = it.toString()













    share|improve this question
























      1












      1








      1








      I have the following code to define a tableview with specific cells changing color depending on condition.



      How I can define a typesafe stylesheet class and apply it to current code preventing the duplication in future?



      class MonitorView : View("Monitor") 
      override val root = borderpane
      center = tableview<ServerModel>
      items = readConfiguration().observable()
      readonlyColumn("Environment", ServerModel::env)
      readonlyColumn("Host", ServerModel::host)
      readonlyColumn("Port", ServerModel::port)
      readonlyColumn("Application Name", ServerModel::appName)
      column("Is online", ServerModel::isReachable).cellFormat
      styleDependingOnBoolean(it)
      graphic = hbox
      button("Restart").action
      isDisable = true






      private fun TableCell<ServerModel, Boolean>.styleDependingOnBoolean(it: Boolean)
      if (it)
      style = "-fx-background-color:#00b200; -fx-text-fill:white"
      text = it.toString()
      else
      style = "-fx-background-color:#8b0000; -fx-text-fill:white"
      text = it.toString()













      share|improve this question














      I have the following code to define a tableview with specific cells changing color depending on condition.



      How I can define a typesafe stylesheet class and apply it to current code preventing the duplication in future?



      class MonitorView : View("Monitor") 
      override val root = borderpane
      center = tableview<ServerModel>
      items = readConfiguration().observable()
      readonlyColumn("Environment", ServerModel::env)
      readonlyColumn("Host", ServerModel::host)
      readonlyColumn("Port", ServerModel::port)
      readonlyColumn("Application Name", ServerModel::appName)
      column("Is online", ServerModel::isReachable).cellFormat
      styleDependingOnBoolean(it)
      graphic = hbox
      button("Restart").action
      isDisable = true






      private fun TableCell<ServerModel, Boolean>.styleDependingOnBoolean(it: Boolean)
      if (it)
      style = "-fx-background-color:#00b200; -fx-text-fill:white"
      text = it.toString()
      else
      style = "-fx-background-color:#8b0000; -fx-text-fill:white"
      text = it.toString()










      javafx kotlin tornadofx






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 12:56









      ashurashur

      1,48383862




      1,48383862






















          2 Answers
          2






          active

          oldest

          votes


















          0














          If I understood correctly, you are looking for something like the following;



          javafxNode.getStyleClass().add("myCssClass");
          // passing true here will activate your css code below
          javafxNode.pseudoClassStateChanged("myPseudoClass",yourBoolean);


          In your CSS file:



          .myCssClass:myPseudoClass
          -fx-text-fill:white






          share|improve this answer
































            0














            You can create a type safe stylesheet and create a selector for this connectivity column which has the default background color. Then add another selector called reachable which overrides this color, like so:



            class MyStyles : Stylesheet() 
            companion object
            val reachable by cssclass()
            val connectivityColumn by cssclass()


            init
            connectivityColumn
            backgroundColor += c("#8b0000")

            connectivityColumn and reachable
            backgroundColor += c("#00b200")





            Make sure this column gets the connectivityColumn class, and toggle the reachable state using toggleClass:



            column("Reachable", Server::reachableProperty) 
            addClass(MyStyles.connectivityColumn)
            cellFormat
            toggleClass(MyStyles.reachable, item)
            graphic = hbox
            button("Restart")





            Note that this only updates the color when the tableview redraws. If you need to update the color based on external events when the tableview doesn't redraw, either fire an event to redraw it, or use a binding instead. If you get a way with the first approach I would recommend it as it doesn't attach any listeners.






            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044340%2ftypesafe-stylesheet-for-tableviews-cell-depending-on-condition%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              If I understood correctly, you are looking for something like the following;



              javafxNode.getStyleClass().add("myCssClass");
              // passing true here will activate your css code below
              javafxNode.pseudoClassStateChanged("myPseudoClass",yourBoolean);


              In your CSS file:



              .myCssClass:myPseudoClass
              -fx-text-fill:white






              share|improve this answer





























                0














                If I understood correctly, you are looking for something like the following;



                javafxNode.getStyleClass().add("myCssClass");
                // passing true here will activate your css code below
                javafxNode.pseudoClassStateChanged("myPseudoClass",yourBoolean);


                In your CSS file:



                .myCssClass:myPseudoClass
                -fx-text-fill:white






                share|improve this answer



























                  0












                  0








                  0







                  If I understood correctly, you are looking for something like the following;



                  javafxNode.getStyleClass().add("myCssClass");
                  // passing true here will activate your css code below
                  javafxNode.pseudoClassStateChanged("myPseudoClass",yourBoolean);


                  In your CSS file:



                  .myCssClass:myPseudoClass
                  -fx-text-fill:white






                  share|improve this answer















                  If I understood correctly, you are looking for something like the following;



                  javafxNode.getStyleClass().add("myCssClass");
                  // passing true here will activate your css code below
                  javafxNode.pseudoClassStateChanged("myPseudoClass",yourBoolean);


                  In your CSS file:



                  .myCssClass:myPseudoClass
                  -fx-text-fill:white







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 12 at 14:09

























                  answered Mar 7 at 13:44









                  NikiforosNikiforos

                  338215




                  338215























                      0














                      You can create a type safe stylesheet and create a selector for this connectivity column which has the default background color. Then add another selector called reachable which overrides this color, like so:



                      class MyStyles : Stylesheet() 
                      companion object
                      val reachable by cssclass()
                      val connectivityColumn by cssclass()


                      init
                      connectivityColumn
                      backgroundColor += c("#8b0000")

                      connectivityColumn and reachable
                      backgroundColor += c("#00b200")





                      Make sure this column gets the connectivityColumn class, and toggle the reachable state using toggleClass:



                      column("Reachable", Server::reachableProperty) 
                      addClass(MyStyles.connectivityColumn)
                      cellFormat
                      toggleClass(MyStyles.reachable, item)
                      graphic = hbox
                      button("Restart")





                      Note that this only updates the color when the tableview redraws. If you need to update the color based on external events when the tableview doesn't redraw, either fire an event to redraw it, or use a binding instead. If you get a way with the first approach I would recommend it as it doesn't attach any listeners.






                      share|improve this answer



























                        0














                        You can create a type safe stylesheet and create a selector for this connectivity column which has the default background color. Then add another selector called reachable which overrides this color, like so:



                        class MyStyles : Stylesheet() 
                        companion object
                        val reachable by cssclass()
                        val connectivityColumn by cssclass()


                        init
                        connectivityColumn
                        backgroundColor += c("#8b0000")

                        connectivityColumn and reachable
                        backgroundColor += c("#00b200")





                        Make sure this column gets the connectivityColumn class, and toggle the reachable state using toggleClass:



                        column("Reachable", Server::reachableProperty) 
                        addClass(MyStyles.connectivityColumn)
                        cellFormat
                        toggleClass(MyStyles.reachable, item)
                        graphic = hbox
                        button("Restart")





                        Note that this only updates the color when the tableview redraws. If you need to update the color based on external events when the tableview doesn't redraw, either fire an event to redraw it, or use a binding instead. If you get a way with the first approach I would recommend it as it doesn't attach any listeners.






                        share|improve this answer

























                          0












                          0








                          0







                          You can create a type safe stylesheet and create a selector for this connectivity column which has the default background color. Then add another selector called reachable which overrides this color, like so:



                          class MyStyles : Stylesheet() 
                          companion object
                          val reachable by cssclass()
                          val connectivityColumn by cssclass()


                          init
                          connectivityColumn
                          backgroundColor += c("#8b0000")

                          connectivityColumn and reachable
                          backgroundColor += c("#00b200")





                          Make sure this column gets the connectivityColumn class, and toggle the reachable state using toggleClass:



                          column("Reachable", Server::reachableProperty) 
                          addClass(MyStyles.connectivityColumn)
                          cellFormat
                          toggleClass(MyStyles.reachable, item)
                          graphic = hbox
                          button("Restart")





                          Note that this only updates the color when the tableview redraws. If you need to update the color based on external events when the tableview doesn't redraw, either fire an event to redraw it, or use a binding instead. If you get a way with the first approach I would recommend it as it doesn't attach any listeners.






                          share|improve this answer













                          You can create a type safe stylesheet and create a selector for this connectivity column which has the default background color. Then add another selector called reachable which overrides this color, like so:



                          class MyStyles : Stylesheet() 
                          companion object
                          val reachable by cssclass()
                          val connectivityColumn by cssclass()


                          init
                          connectivityColumn
                          backgroundColor += c("#8b0000")

                          connectivityColumn and reachable
                          backgroundColor += c("#00b200")





                          Make sure this column gets the connectivityColumn class, and toggle the reachable state using toggleClass:



                          column("Reachable", Server::reachableProperty) 
                          addClass(MyStyles.connectivityColumn)
                          cellFormat
                          toggleClass(MyStyles.reachable, item)
                          graphic = hbox
                          button("Restart")





                          Note that this only updates the color when the tableview redraws. If you need to update the color based on external events when the tableview doesn't redraw, either fire an event to redraw it, or use a binding instead. If you get a way with the first approach I would recommend it as it doesn't attach any listeners.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 12 at 14:45









                          Edvin SyseEdvin Syse

                          5,2571021




                          5,2571021



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044340%2ftypesafe-stylesheet-for-tableviews-cell-depending-on-condition%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              1928 у кіно

                              Захаров Федір Захарович

                              Ель Греко