bdunkleysmith Active Member Licensed User Longtime User Jul 18, 2015 #1 Is it possible to center align text in a textarea? I have used some formatting such as: Code: Copy 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.
Is it possible to center align text in a textarea? I have used some formatting such as: Code: Copy 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.
R Roycefer Well-Known Member Licensed User Longtime User Jul 18, 2015 #2 https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#text Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jul 19, 2015 #3 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? Upvote 0
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?
bdunkleysmith Active Member Licensed User Longtime User Jul 19, 2015 #4 Thanks Roycefer, I did try without success: Code: Copy 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
Thanks Roycefer, I did try without success: Code: Copy 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.
bdunkleysmith Active Member Licensed User Longtime User Jul 19, 2015 #5 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: Code: Copy 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
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: Code: Copy 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?
rwblinn Well-Known Member Licensed User Longtime User Jul 19, 2015 #6 Hi, please try this example using JavaObject. Code: Copy Sub Process_Globals Private rechtangleMain As Node Code: Copy 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: Copy .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 Upvote 0
Hi, please try this example using JavaObject. Code: Copy Sub Process_Globals Private rechtangleMain As Node Code: Copy 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: Copy .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.
bdunkleysmith Active Member Licensed User Longtime User Jul 20, 2015 #7 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 Upvote 0
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.