B4J Question How to strikethrough the text of a label

Tchou

New Member
Licensed User
Longtime User
Hello Everyone!

I try to have a horizontal line in the middle of the text of my label with -fx-text-decoration: line-through; in the style. It is not working.

B4X:
#Region Project Attributes
   #MainFormWidth: 300
   #MainFormHeight: 200
#End Region

Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private styleNormal As String = "-fx-background-color: #FFFFFF;-fx-font-family: Arial;-fx-font-size: 30px;-fx-font-weight: bold;-fx-padding:0"
   Private styleSrike As String = $"-fx-background-color: #FFFFFF;-fx-font-family: Arial;-fx-font-size: 30px;-fx-font-weight: bold;-fx-padding:0;
   -fx-text-decoration: line-through; "$
  End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.show()
   'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
   MainForm.Show
   Dim lblNormal As Label
   lblNormal.Initialize("l1")
   lblNormal.Style=styleNormal
   lblNormal.text="my text"
   MainForm.RootPane.AddNode(lblNormal,10,10,200,40)
   
   Dim lblStroke As Label
   lblStroke.Initialize("l2")
   lblStroke.Style=styleSrike
   lblStroke.text="my text"
   MainForm.RootPane.AddNode(lblStroke,10,50,200,40)
End Sub


'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
   Return True
End Sub

I expet the second label to be strikethrough but it is not

Thanks for your help
 

Tchou

New Member
Licensed User
Longtime User
Thanks Erel,
Your suggestion can solve partly my problem.
In fact, I need somewhere in my code, to have the possibility to Strikethrough and unStrikethrough according to my logic. That seems not possible with your approach
 
Upvote 0

Tchou

New Member
Licensed User
Longtime User
Sorry, I understand I was not clear enough

I want that when a text is clicked, I do something, and possibly, I change the Strikethrough status of the clicked text.

When the text is a label I expected do something like that:
B4X:
Sub Process_Globals
....
   Private styleNormal As String = "-fx-background-color: #FFFFFF;-fx-font-family: Arial;-fx-font-size: 30px;-fx-font-weight: bold;-fx-padding:0"
   Private styleSrike As String = $"-fx-background-color: #FFFFFF;-fx-font-family: Arial;-fx-font-size: 30px;-fx-font-weight: bold;-fx-padding:0;
   -fx-text-decoration: line-through; "$
...
End Sub

Sub AppStart (Form1 As Form, Args() As String)
...
   Dim lbl_to_click As Label
   lbl_to_click.Initialize("l1")
   lbl_to_click.Style=styleNormal
   lbl_to_click.text="my text"
   lbl_to_click.tag="initial tag"
...
End Sub

Sub l1_mouseclicked(EventData As MouseEvent)
   Private l As Label = Sender
   If sometest(l.tag) Then
       do_something
       l.style=styleNormal
   Else
       do_something_else
       l.style=styleSrike
   End If
    l.tag = calculated_tag
End Sub

which is not working because the -fx-text-decoration: line-through; has no effect.

With your approach, the text ends-up in a pane and I miss the possibility to give an event name at initialize time, as well as I miss the tag.

(I will now try with a transparent button on top of the pane ... but may be there is a more elegant solution)
 
Upvote 0
Top