I've started using gbui and am very happy with it, it's quite intuitive and easy to work with.
However, I've tried to find how to change the colour of a BLabel's text dynamically and it's not working.
I tried using
in the bss-file for online_label and offline_label respectively.
This works once, that is, if you switch from no style class to one of them, the colour changes, but if you then want to change the colour again (e.g. from offline_label to online_label) nothing happens.
How can I change styleSheets several times for one BComponent or is there another way to change colour and other properties of the text?
right now there's no way to change a style sheet for multiple components since the bss is loaded at runtime and stored.
Let me see if I can come up with a solution for you. you can't just change the styleclass for a component without rerendering it in some way. I'll have an answer shortly
Thank you standtrooper, really quick reply!
I look forward to reading what you come up with.
However, I might not have explained it well enough.
I'm using one label that I want to change the colour of the text for when a client connects to a server.
If the server is offline, I want it to be red, if it's online green.
So if the server is offline, then goes online, it should change from red to green.
With what I've tried (using setStylesheet), it changes from black (no custom stylesheet, just the BuiSystem one) to (the stylesheet for) red (if offline), but when it notices that the server is online, it won't change to (the stylesheet for) green (although the text changes, so it does do the function call).
so, right now there's no way to change the color at runtime…but, there is a way to do it, a little differently.
I've just checked in another "test" called ColorTransitionTest to svn to look at the src for.
So, when the window is rendered the first time, the only way to change something again is to shut it down make the change and then start it back up…not enjoyable. I'd like for it to work like CSS does on a webpage, but doesn't fit with my week so far.
So, you have to detach the object. you can create a copy if that's easier, then detach it from the window, make whatever style change you want and then reattach it to the window.
I used the following bss attributes to make this change (the first is white, the 2nd is actually red)
I added them to the end of style2.bss and then dropped it into the rsrc jar.
when it loads you'll see text that says "click" and a button that says "click" click the button the text changes color from white to red.
As of right now that's the only way to do it.
if the text is static, no problem. If the text is dynamic, then you have to store the text and make your changes adding the text to the Label or whatever...
it's not the greatest way to make the change.
That got it working!
True, it's not the most straightforward way to change colour of a text, but it works!
A thousand thanks!