JavaFX - Label text color on negative text value - javafx-8

I would like to change text color of my Label in case its text value is a negative number (or starts with a '-'). Is there a proper binding to make it works?

No, you need to create it yourself, e.g.
Label label = ...
IntegerExpression value = ...
label.textProperty().bind(value.asString());
label.textFillProperty().bind(Bindings.when(value.lessThan(0))
.then(Color.RED)
.otherwise(Color.BLACK));
If you've don't have a expression that allows you to create a condition in this way you could of course also create a binding that depends on the Label's text property:
Label label = ...
label.textFillProperty().bind(Bindings.createObjectBinding(() -> label.getText().startsWith("-")
? Color.RED
: Color.BLACK,
label.textProperty()));

Related

How to use .byCharWrapping for a specific character?

How would I do something similar to .byCharWrapping for a label where the text is in the form of "soccer", "basketball", "hockey", "volleyball" and I want to wrap by commas so that the displayed text would be e.g. "soccer", "basketball", "hockey" if "volleyball" doesn't fit within the label.
I think you can fit your text with another solution , you can also fit your text in label with font size : like below line and you can put it on if conditions :
label.font = UIFont.systemFont(ofSize: 17)
You can determine the actual width of string with font, then do whatever you want if that width is less than labels width.
See here size(withAttributes:)

'R Cannot be assigned to' error in Roblox Lua

I am trying to change the color value of a textlabel. I am doing so using:
script.Parent.Parent.toggled2.SurfaceGui.SIGN.TextColor3.R = 0
script.Parent.Parent.toggled2.SurfaceGui.SIGN.TextColor3.G = 255
script.Parent.Parent.toggled2.SurfaceGui.SIGN.TextColor3.B = 0
basically it navigates to a button (a part, parent of the script) then to the group its in, then to a part with the text (in this case toggled2) then to the surfacegui inside then the textlabel (which is named SIGN) it then modifies the TextColor3 attribute 3 times at once, adjusting all the R,G,B values.
Why wont it let me alter the value? do i have to do something like :new() or .new()?
In order to assign a value to the TextColor3 property, you have to pass a Color3 object :
local sign = script.Parent.Parent.toggled2.SurfaceGui.SIGN
sign.TextColor3 = Color3.new(0, 255, 0)

Suppress a Text Object Based on Field Value in Object

I have a Text Object that contains a text string followed by a database field Max Weight {table.field}
I want to suppress all of the Text Object whenever {table.field} = 0.
I tried the following formula under Format Text > Common > Suppress
if {table.field} = 0 then true else false
What I get is the field value within the text object either on or off while the text is always suppressed. What do I need to do to make this work? Thanks.
You can try 2 different solutions:
1) Keeping your Max Weight label, create a new Formula in the 'Formula Fields' then enter this code:
if {table.field} = 0 then '' else ToText({table.field})
2) Supressing all text, you have to create a new Formula too, but type this:
if {table.field} = 0 then '' else 'Max Weight ' + ToText({table.field})
This second way, you will create a label that will only appears when your conditions happens, and you must replace the old TextObject with this new Formula. This will cause a blank area, because no text and no weight will show, but it looks like exactly what you need.
I just tested here and it's working. Note that both 'spaces' are in the document. Attached is an image that may help you find the formulas section. Hope you can use it.

how to set textfield size fix macos swift

I have one textfield "A" with width 150. but whenever I am passing more characters to textfield "A", it is getting overlapped on other textfield "B" characters.
I want textfield "A" to be fixed size and scrollable(mostly right and left).
Thanks in advance.
You should use Auto-Layeout in your storybook. Set fixed width, trailing space and leading space to your text field.
I have added the Auto-Layeouts to my textfields and I have followed below steps:
1) Selected the label.
2) Go to attributes inspector.
3) Select 'Line Breaks' and choose an option Truncate Tail
4) now I can see the text without overlapping with another textField.
Note: But still I am not able to view/Scoll the full text.
Just found this piece of code. It might help you
scrollView.hasHorizontalScroller = true
textView.maxSize = NSMakeSize(CGFloat(FLT_MAX), CGFloat(FLT_MAX))
textView.isHorizontallyResizable = true
textView.textContainer?.widthTracksTextView = false
textView.textContainer?.containerSize = NSMakeSize(CGFloat(FLT_MAX), CGFloat(FLT_MAX))

How to change cell color in a listgrid

I want to change font and color of a specific cell in a ListGrid.
I succeeded to change the color of the entire row with the following lines, but not of a single row:
for (ListGrid table : tables)
{
ListGridField[] columns = table.getFields();
for (Record record : table.getRecords())
{
....
record.setAttribute("cssText",
"font-weight:bold; font-size:80%; color:#FF3300;");
I don't want to use getCellCSSText function, i tried the following but it didn't work:
ListGridField gridfield = table.getField(columns[1].getName());
gridfield.setAttribute("cssText",
"font-weight:bold; font-size:80%; color:#FF3300;");
table.refreshFields();
I'm sure there is a better way to do it. But this is how i did it:
I added a hidden column to the table, that contain the color.
In getCellCSSText i read the color and the column name and set the color.
Is there a way to add an invisible parameter to a ListGridRecord? So that i won't add an entire column.