5 Replies Latest reply: Sep 4, 2013 11:38 AM by James_D RSS

    Cutomize a disabled TextField

    917173

      Hello,

       

      I'm using a disabled text field.

      But the text color used for this is to clear, it becomes not visible on some screens.

      How possible to change it.

      I tried to use labels, but i did not feel at ease with it.

      Any one could suggest me how to resolve this problem.

       

      Thank you.

        • 1. Re: Cutomize a disabled TextField
          James_D

          This is controlled by the .text-input:disabled rule in css; by default the opacity is set to 0.4. You can override it in an external style sheet with the rule

           

          .text-input:disabled {
                -fx-opacity : 0.6 ;
          }
          

           

          (for example).

           

          In JavaFX 2.2 a whole slew of controls actually have their "disabled" opacity set to the lookup value -fx-disabled-opacity. So you can override this value for everything with a single rule:

           

          -fx-disabled-opacity: 0.6 ;

           

          However, this doesn't seem to work with the default stylesheet in JavaFX 8.

          • 2. Re: Cutomize a disabled TextField
            917173

            Hello,

            Thank you James D for your answer.

            I have 2 questions:

            1/ I did not understand what did you mean by "default stylesheet".

            2/What i supposed to do with JavaFX8 to solve this issue.

             

            Thank you.

            • 3. Re: Cutomize a disabled TextField
              James_D

              The css code above (.text-input:disabled { ...} ) should work in both JavaFX 2.2.x and JavaFX 8. In JavaFX 8 there's just no nice way (at least that's obvious to me) to change the opacity for all disabled controls at once.

               

              The default stylesheet in JavaFX 2.2.x is caspian.css. The default stylesheet for JavaFX 8 is modena.css. You can extract these from the jfxrt.jar files from the JDK distribution, or you can see a current version of modena.css here.

              • 4. Re: Cutomize a disabled TextField
                917173

                Yes, i understand now. Thank you a lot.

                But i still have one question. Once i modified the defaut style sheet. I just have to regenerate the jar file?

                • 5. Re: Cutomize a disabled TextField
                  James_D

                  No, you misunderstood.

                   

                  Don't modify the default style sheet. Just provide your own external style sheet that overrides the rules you want to change. I was only indicating where to find the defaults so you could see what they did. So all you need is the css code I gave in the first reply (three lines) as an external style sheet. See the tutorial.