B4J Question Canvas DrawText - how to apply alignment?

Jim Brown

Active Member
Licensed User
Longtime User
I can't seem to get this to work:

B4J code

B4X:
mycanvas.DrawText("hello",10,10,fx.DefaultFont,fx.Colors.Blue,"LEFT")

The error message is "too many parameters"
If I remove the "LEFT" I get "missing parameter"

How do you apply the alignment parameter?

The docs say:

DrawText (Text As String, x As Double, y As Double, Font As javafx.scene.text.Font, Paint As javafx.scene.paint.Paint, Alignment As javafx.scene.text.TextAlignment)
Draws the text.
Text - The text that will be drawn.
x - The origin X coordinate.
y - The origin Y coordinate.
Font - The text font.
Paint - Drawing color.
TextAlignment - Sets the alignment relative to the origin. One of the following values: LEFT, CENTER, RIGHT.
 
Last edited:

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Jim, for asking the question exactly as I would have.

Thank you, Steve - you are a treasure of knowledge.
 
Upvote 0

TorontoJim

Member
Licensed User
Longtime User
I'm also getting an error with the DrawText(). It's telling me "Left" is wrong. I've tried:
"Left"
"LEFT"
Left
LEFT


B4X:
Sub paneDayBuilderCanvas_Resize (Width As Double, Height As Double)
    Dim timeFont As Font
    timeFont = fx.CreateFont("Verdana,Tahoma,Arial", 32, True, False)
	canvasDayDesigner.ClearRect(0, 0, Width, Height)
	'Hours hash lines; Left is 85; Right is width - 35
	Dim dblCanvas0000 As Double = 85
	Dim dblCanvasX1Hr As Double
	dblCanvasX1Hr = ((Width - 120.00) / 24.00)
	canvasDayDesigner.DrawLine(dblCanvas0000, 20.00, dblCanvas0000, (Height - 50), fx.Colors.Gray, 2.00)
	For i = 1 To 24
		If i mod 6 = 0 Then
			canvasDayDesigner.DrawLine(dblCanvas0000 + (dblCanvasX1Hr * i), 20.00, dblCanvas0000 + (dblCanvasX1Hr * i), (Height - 50), fx.Colors.Gray, 2.00)
		Else
			canvasDayDesigner.DrawLine(dblCanvas0000 + (dblCanvasX1Hr * i), 20.00, dblCanvas0000 + (dblCanvasX1Hr * i), (Height - 50), fx.Colors.ARGB(100, 140, 140, 140), 1.00)
			canvasDayDesigner.DrawText(i, dblCanvas0000 + (dblCanvasX1Hr * i), Height - 25, timeFont, fx.Colors.Gray, "Left")
		End If
	Next
End Sub


This is the error I'm getting on the Draw Text:

B4X:
java.lang.IllegalArgumentException: No enum constant javafx.scene.text.TextAlignment.Left


Canvas is working great, lines are drawing no problem. It's just this that (so far) is buggering up for me.
 
Upvote 0
Top