B4J Question Center align text in textarea

bdunkleysmith

Active Member
Licensed User
Longtime User
Is it possible to center align text in a textarea?

I have used some formatting such as:

B4X:
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.
 

bdunkleysmith

Active Member
Licensed User
Longtime User
Thanks Roycefer, I did try without success:

B4X:
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.
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime 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 https://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:

B4X:
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?
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

please try this example using JavaObject.

B4X:
Sub Process_Globals
  Private rechtangleMain As Node

B4X:
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:
B4X:
.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:
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime 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:
Upvote 0
Top