B4J Question load JGauge in code (runtime)

jayel

Active Member
Licensed User
Longtime User
Hello,

I want to dynamically load jgauges on a panel.
B4X:
Sub GetListTempSensors()
    Dim myselect As String
    Dim sql As SQL = DBMdomotica.GetSQL
    myselect = "SELECT tblinputs.* 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
       
        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.modulecode = resultdata.Get("idmodule")
            mytemp.tempvalue = 0
           
            Dim mygauge As Gauge
            mygauge.Initialize("")
            mygauge.Tag = mytemp.modulecode
           
           
            InitGauge(mygauge,-5,50,mytemp.tempvalue,1,mytemp.beschrijving,"°C","DASHBOARD","")
            listTemp.Add(mygauge)
       
            PanelMain.AddNode(mygauge,(r+1)*100,100,200,200)
           
           
        Next
    End If
   
End Sub
Sub InitGauge(s_gauge As Gauge, minValue As Double, maxValue As Double, Value As Double, decimal As Double, Title As String, Unit As String, Skin As String, subTitle As String )
   
   

    Dim jo As JavaObject = s_gauge


    jo.RunMethod("setSkinType", Array(Skin))
    jo.RunMethod("setMinValue", Array(minValue))
    jo.RunMethod("setMaxValue", Array(maxValue))
    jo.RunMethod("setValue", Array(Value))

    jo.RunMethod("setTitle", Array(Title))
    jo.RunMethod("setUnit", Array(Unit))
    jo.RunMethod("setSubTitle", Array(subTitle))
    jo.RunMethod("setForegroundBaseColor", Array(fx.Colors.RGB(82,82,82))) ' Color for title, subtitle, unit, value, tick label, zeroColor
    jo.RunMethod("setUnitColor", Array(fx.Colors.RGB(82,82,82)))
    jo.RunMethod("setTitleColor", Array(fx.Colors.RGB(82,82,82)))
    jo.RunMethod("setSubTitleColor", Array(fx.Colors.RGB(82,82,82)))


    jo.RunMethod("setValueColor", Array(fx.Colors.RGB(82,82,82)))
    jo.RunMethod("setBarBackgroundColor", Array(fx.Colors.RGB(255,64,64)))
    jo.RunMethod("setBarColor", Array(fx.Colors.RGB(125,125,125)))

    jo.RunMethod("setDecimals", Array(1))
End Sub

I get this error.
 

jayel

Active Member
Licensed User
Longtime User
OK

I created a layout file with 1 gauge.
B4X:
Sub GetListTempSensors()
    Dim myselect As String
    Dim sql As SQL = DBMdomotica.GetSQL
    myselect = "SELECT tblinputs.* 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
       
        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.modulecode = resultdata.Get("idmodule")
            mytemp.tempvalue = 0
           
           
            PanelMain.LoadLayout("Gauge")
            'InitGauge(mygauge,-5,50,mytemp.tempvalue,1,mytemp.beschrijving,"°C","DASHBOARD","")
            listTemp.Add(mytemp)
       
           
           
           
        Next
    End If
   
End Sub

How can I get the gauge control to change it with initGauge?
And how can I change the left and top of the layoutfile?

Sorry no experience with B4J UI solution.
 
Upvote 0

jayel

Active Member
Licensed User
Longtime User
B4X:
Sub GetListTempSensors()
    Dim myselect As String
    Dim sql As SQL = DBMdomotica.GetSQL
    myselect = "SELECT tblinputs.* 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
       
        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.modulecode = resultdata.Get("idmodule")
            mytemp.tempvalue = 0
           
            '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 = mygauge.BaseView
'                    mypane.Left = (r+1) * mypane.Width
'                    mypane.Top = 100
'                    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
Gives me an error :
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
There are other objects in PanelMain apart from Gauge's which you cannot assign to an object of type Gauge.

You can test for the correct type using:

B4X:
    If n Is Gauge Then
    Dim MyGauge As Gauge = n
Else
     '.... Do whatever
End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…