B4J Question [Solved] How can I display the colors in this image?

Mark Read

Well-Known Member
Licensed User
Longtime User
I am working on an app to decompile a configuration file and show object configuration. I would like to show the data in a panel like the original program. No events are required, just show the data.

For example, the gauge object has the properties as detailed in the yellow fields in the image. Each property has a color. My question: How can I show the gauge colors and put a black border around the selected color (in the image, the dark blue), without creating 28 labels and repeating them 6 times?

Thanks for any help.
 

Mark Read

Well-Known Member
Licensed User
Longtime User
That would work if I could set only the colors in the image. Only these colors are available. I only need to show the selected color, nothing more.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Thanks Erel, will also look at that as an option. For the moment I have a solution.

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
 
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
 
    CreateColors(50,50)
    CreateColors(50,100)
    CreateColors(50,150)
 
End Sub

Sub CreateColors(l As Int, t As Int)
    Private pnGauge As Pane
    pnGauge.Initialize("")
    MainForm.RootPane.AddNode(pnGauge,l,t,270,49)
    Dim mycolors(3,15), mynames(3,15) As String
    mycolors(1,1)="255,255,255"
    mycolors(1,2)="192,192,192"
    mycolors(1,3)="255,0,0"
    mycolors(1,4)="255,255,0"
    mycolors(1,5)="0,255,0"
    mycolors(1,6)="0,255,255"
    mycolors(1,7)="0,0,255"
    mycolors(1,8)="255,0,255"
    mycolors(1,9)="255,128,128"
    mycolors(1,10)="128,255,0"
    mycolors(1,11)="128,255,128"
    mycolors(1,12)="128,128,255"
    mycolors(1,13)="128,255,255"
    mycolors(1,14)="255,128,255"
 
    mycolors(2,1)="0,0,0"
    mycolors(2,2)="128,128,128"
    mycolors(2,3)="128,0,0"
    mycolors(2,4)="128,128,0"
    mycolors(2,5)="0,128,0"
    mycolors(2,6)="0,128,128"
    mycolors(2,7)="0,0,128"
    mycolors(2,8)="128,0,128"
    mycolors(2,9)="255,128,0"
    mycolors(2,10)="255,255,128"
    mycolors(2,11)="0,255,128"
    mycolors(2,12)="128,0,255"
    mycolors(2,13)="0,128,255"
    mycolors(2,14)="255,0,128"
 
    mynames(1,1)="white"
    mynames(1,2)="ltgray"
    mynames(1,3)="red"
    mynames(1,4)="yellow "
    mynames(1,5)="green"
    mynames(1,6)="ltblue"
    mynames(1,7)="blue"
    mynames(1,8)="magenta"
    mynames(1,9)="pink"
    mynames(1,10)="lime"
    mynames(1,11)="pastelgreen"
    mynames(1,12)="ltviolet"
    mynames(1,13)="pastelblue"
    mynames(1,14)="pastelviolet"
 
    mynames(2,1)="black"
    mynames(2,2)="gray"
    mynames(2,3)="dkred"
    mynames(2,4)="brown"
    mynames(2,5)="dkgreen"
    mynames(2,6)="aqua"
    mynames(2,7)="dkblue"
    mynames(2,8)="dkviolet"
    mynames(2,9)="orange"
    mynames(2,10)="ltyellow"
    mynames(2,11)="ltgreen"
    mynames(2,12)="blviolet"
    mynames(2,13)="skyblue"
    mynames(2,14)="hotpink"
    Dim myWidth As Int
    myWidth=15dip
         
    For y=1 To 2
        For x=1 To 14
            Dim cLabel As Label
            cLabel.Initialize("")
            pnGauge.AddNode(cLabel,x*(myWidth+2),(y-1)*(myWidth+2),myWidth, myWidth)
         
            Dim r, g, b As Int
            Dim RGBColor() As String
            RGBColor=Regex.Split(",", mycolors(y,x))
            r=RGBColor(0)
            g=RGBColor(1)
            b=RGBColor(2)
            cLabel.Style=$"-fx-background-color:rgb(${r},${g},${b});"$
             
        Next
    Next
 
    pnGauge.PrefWidth=(x*(myWidth+2))+myWidth        '270
    pnGauge.PrefHeight=((y-1)*(myWidth+2))+myWidth    '49
End Sub

The array mynames I need later, as the color is defined by name, not by RGB. Its not pretty but it does the job.

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…