B4J Question label textalignment

jayel

Active Member
Licensed User
Longtime User
Hello,

B4X:
Sub GetListTempSensors()
    Dim myselect As String
    Dim sql As SQL = DBMdomotica.GetSQL
    myselect = "SELECT tblinputs.*, tblmodules.code FROM tblinputs INNER JOIN tblmodules ON (tblinputs.idmodule = tblmodules.idmodule) WHERE tblmodules.soort = 'a'"        
    
    Dim myresult As List = DBMdomotica.SQLSelect(sql,myselect)
    DBMdomotica.CloseSQL(sql)
   
    If myresult.size > 0 Then
        MainForm.WindowWidth = 20
        MainForm.WindowHeight = 150
        Dim r As Int
        For r = 0 To myresult.Size - 1
            Dim resultdata As Map = myresult.Get(r)
            Dim mytemp As temperatuur
            mytemp.beschrijving = resultdata.Get("beschrijving")
            mytemp.inputid = resultdata.Get("idinput")
            mytemp.idmodule = resultdata.Get("idmodule")
            mytemp.modulecode = resultdata.Get("code")
            mytemp.tempvalue = 0
            Dim mypane As Pane
            mypane.Initialize("")
            mypane.Tag = mytemp.modulecode
           
            Dim mytextlabel As Label
            mytextlabel.Initialize("mytextlabel")
            mytextlabel.Text = mytemp.beschrijving
            mytextlabel.TextSize = 10
            mytextlabel.Id = "myTextLabel"
            mypane.AddNode(mytextlabel,5,5,90,20)
            Dim mylabel As Label
            mylabel.Initialize("myLabel")
            mylabel.Id = "myLabel"
            mylabel.Text = "30 °C"
            mylabel.Tag = mytemp.modulecode
            mylabel.TextSize = 16
            'mylabel.Style = "-fx-text-alignment: justify"
           
            mypane.AddNode(mylabel,5,25,90,40)
            CSSUtils.SetBorder(mylabel,1,fx.Colors.Black,5)
            CSSUtils.SetStyleProperty(mylabel,"-fx-text-alignment","center")
'            CSSUtils.SetStyleProperty(mylabel,"-fx-hpos","center")
'            CSSUtils.SetStyleProperty(mylabel,"-fx-vpos","center")
            CSSUtils.SetBackgroundColor(mylabel, fx.Colors.Yellow)
            PanelMain.AddNode(mypane,r*100,10,100,50)
            MainForm.WindowWidth = MainForm.WindowWidth + 100
'            'Dim mygauge As Gauge
'            'mygauge.Initialize("gauge")
'            'mygauge.Tag = mytemp.modulecode
'            'PanelMain.AddNode("Gauge1",(r+1)*100,100,200,200)
'            PanelMain.LoadLayout("Gauge")
'            For Each n As Node In PanelMain.GetAllViewsRecursive
'                'If n.Id = "Gauge1" Then
'               
'                'Log ("gauge " & n)
'                'Dim mygauge As Gauge = n
'                    Dim mypane As Pane = n
'                    mypane.Left = (r+1) * 100
'                    mypane.Top = 100
'                    Log (r)
''                    InitGauge(mygauge,-5,50,mytemp.tempvalue,1,mytemp.beschrijving,"°C","DASHBOARD","")
'                    Exit
'                'End If
'            Next
            'InitGauge(mygauge,-5,50,mytemp.tempvalue,1,mytemp.beschrijving,"°C","DASHBOARD","")
            listTemp.Add(mytemp)
       
           
           
           
        Next
    End If
   
End Sub

upload_2017-4-3_10-44-4.png


Why isn't my text in the center?

John.
 

stevel05

Expert
Licensed User
Longtime User
Try using
B4X:
myLabel.Alignment = "CENTER"
instead of CSSUtils.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I don't know javafx css well enough, but CSSUtils.SetStyleProperty(MyLabel,"-fx-alignment","center") would also work.

You may be able to find out why if you google "javafx css"
 
Upvote 0
Top