B4J Question Center align text in textarea

Discussion in 'B4J Questions' started by bdunkleysmith, Jul 18, 2015.

  1. bdunkleysmith

    bdunkleysmith Member Licensed User

    Is it possible to center align text in a textarea?

    I have used some formatting such as:

    Code:
    Dim GameClock As TextArea
    GameClock.Style = 
    "-fx-font-size: 48; -fx-font-weight: Bold;"
    but I've not been able to find anything which will control alignment.

    I'd like both horizontal and vertical alignment, but would be happy with just horizontal alignment.
     
  2. Roycefer

    Roycefer Well-Known Member Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that you can change the TextArea alignment. Why do you use TextArea instead of Label? Does it need to be edited?
     
  4. bdunkleysmith

    bdunkleysmith Member Licensed User

    Thanks Roycefer, I did try without success:

    Code:
    GameClock.Style = "-fx-font-alignment: center;"
    as per the reference, but I believe Erel is correct and control of alignment is not possible.

    I only used TextArea as it was already in a form I was using as a template for a new project, but as you suggest Erel, for my purpose a Label would be OK.

    Thanks for your support again.
     
  5. bdunkleysmith

    bdunkleysmith Member Licensed User

    Erel I changed to use Labels and have used Rectangles to provide backgrounds of various colors. However I want to change the Rectangle color under program control, however none of the methods I've tried work.

    For instance I saw an example where a Rectangle was assigned as a JavaObject here http://www.b4x.com/android/forum/threads/add-rectangles-to-map-use-them-as-limits.48139/ which I thought may be the right direction, but when I:

    Code:
    Dim jo As JavaObject = RinTeamFoulsRect
    it does not recognise RinTeamFoulsRect as a valid value even though I have set that as the ID in SceneBuilder.

    Do I need to set the ID some other way and what would the appropriate jo.RunMethod code to change the Rectangle Fill color?
     
  6. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    please try this example using JavaObject.

    Code:
    Sub Process_Globals
      
    Private rechtangleMain As Node
    Code:
    Dim joRect As JavaObject = rechtangleMain
    'Set the fill color to yellow
    joRect.RunMethod("setFill"Array(fx.Colors.Yellow))
    BTW: Just in case, if has to be a textarea with centered text, this can be done by defining in the files folder a css file with following entry:
    Code:
    .text-area *.text {
        -fx-text-alignment: center;
    }
    Assign the css file as a stylesheet to the textarea. Tested this solution by using the JavaFX SceneBuilder.
     
    Last edited: Jul 19, 2015
    Erel likes this.
  7. bdunkleysmith

    bdunkleysmith Member Licensed User

    Thanks Robert.

    Your example works great and if I need to use TextArea in the future I'll try your other suggestion.

    Once again thanks for your support - I am continually amazed by the support this site offers users.
     
    Last edited: Jul 20, 2015
    UFOCoder13 and rwblinn like this.
Loading...