B4J Question Set color of text box programmatically?

basefilm

Member
Using B4J 10.0 64-bit on Windows 11.

I seem to have run into a parameter that is in the internal designer, but not accessible, built-in, programmatically.

In this case it is the color of a text box. I thought this would be trivial.

In the Internal designer, you can just select the color from a handy RGB palette, or from a drop-down of named colors. Great!

Is there a txtbox.color= or txtbox.setcolor() or txtbox.backgroundcolor or similar available in the code? From what I can find, no.

I did some searching in the forums. Near as I can tell, I need to load an additional Java library to do this? That can't be right, can it?

In my searching I came across B4XXUIViews and its "B4XFloatTextField", which is an enhanced version of the text field, which has:
B4XFloatTextField1.mBase.Color=nn (this one's popup help says it "Gets or sets the background color")
and
B4XFloatTextField1.mBase.SetColorAndBorder(a,b,c,d) (this one's popup help says it "sets the background and border color")

(The help doesn't say what the range of valid values is for either. Where is that info?)

Anyway, I created a new project with the defaults, added that library, added a plain B4XFloatTextField to my project, but no matter what number I use, nothing changes. The B4XFloatText field doesn't change, the border doesn't change, it doesn't matter what numbers I use, not for the background or the border.

sample:
Private Sub Button1_Click
    'xui.MsgboxAsync("Hello world!", "B4X")
    Private bgcolor,borderwidth,bordercolor,borderradius As Int
    bgcolor=Rnd(0,1024)
    borderwidth=Rnd(0,20)
    bordercolor=Rnd(1024,32768)
    borderradius=Rnd(0,45)
    B4XFloatTextField1.mBase.Color=bgcolor
    B4XFloatTextField1.mBase.SetColorAndBorder(bgcolor,borderwidth,bordercolor,borderradius)
    B4XFloatTextField1.TextField.Color=bgcolor
    B4XFloatTextField1.Text=bgcolor & ", " & borderwidth & ", " & bordercolor & ", " & borderradius
End Sub

That's when I stopped. I must just be approaching this fundamentally wrong. I'm on some kind of wild goose chase. Any help? TIA!

I've attached an image if it isn't clear what I'm trying to do, a GIF of what the test app output is, and the .zip of the test app.
 

Attachments

  • paintdotnet_rcoByYeDG0.png
    paintdotnet_rcoByYeDG0.png
    8.4 KB · Views: 16
  • java_fXaO2lC1go.gif
    java_fXaO2lC1go.gif
    107.5 KB · Views: 17
  • Testxuidesigner.zip
    3.2 KB · Views: 9

klaus

Expert
Licensed User
Longtime User
For a standard TextField you should declare it as a B4XView:
B4X:
Private TextField1 As B4XView
And use:
Either:
B4X:
TextField1.Color = xui.Color_Blue
Or:
B4X:
TextField1.SetColorAndBorder(xui.Color_Blue, 2, xui.Color_Red, 10)

You could also use this, if you have declared TextField1 as a TextField, but I would not recommend it:
B4X:
TextField1.As(B4XView).Color = xui.Color_Blue
 
Upvote 0
Top