TextButton doesn't update its label text - libgdx

I have a TextButton inside a Stack and after I change its style and update its text I see no text in the Label. I even used the setText method in render(float delta) but no luck. I should mention that prior to calling the setText method the Stack also contained a picture, that completely covered the labell cell of the TextButton, which I simply removed.
Why isn't the text getting updated?

If anyone's having this issue make sure you don't have the label set to hide(). I had it hidden for when a lock picture was displayed over the TextButton. Adding the line below solved my issue:
button.getLabel().addAction(Actions.show());

Related

Libgdx, Label doesn't show any text

I hope this question is not too trivial, but i can not figure out why the label I have created won't show any text (the label is placed below the settings button):
edit: i am using version 1.9.3
Label currentSong = new Label("test", new Label.LabelStyle(Assets.instance.fonts.defaultSmall,
Color.BLUE));
table.add(currentSong);
if (debugEnabled) layer.debug();
return table;
I tested this code and it works. You might have problems with your font. Is the button texts a image or you are using this font?
One possible problem is that you dispose your font somewhere before using it. So it's all black and you cannot see it because you are using a black background.
Paste all your code here. At least the part you allocate/dispose the font and you create the table, the buttons and this screen...
Some code you should call:
stage.addActor(table); in the show() method.
stage.act(delta);
stage.draw();
In the render() method.
I know you probably called everything correctly, otherwise the table wouldn't apear. So check the font dispose. If you still needs help, we need the source...

setText jolts TextButton at inital position for a microsecond or two while movement is happening

I have an actor and I'm moving it by using moveTo(destinationx, destinationy, time).
The problem is that the actor is a TextButton and I need to change the text while the movement is happening and this poses a serious problem. It seems setText calls invalidate and invalidateHierarchy so when the method is called the position of the TextButton is reset to the initial position for a while so that the movement proceeds with a jolt (jump) of the text button position (position set at initialization - .center()).
All the dynamics of my actor movements are running as planned as long as I don't modify the text while Actions.moveTo is still running. If I do modify it then I see a jolt of the text at the moment I call setText.
How can I solve this pb?
I was able to reproduce your problem by placing a Button in a Table and using moveTo actions on the Button. The problem is that when a widget belongs to a Table, the Table is responsible for controlling the widget's position and size, so actions that affect the position will not work correctly.
If you are moving a widget around the screen to arbitrary positions, it doesn't make sense for you to keep it in a static Table anyway. If you add the Button directly to the stage, the problem goes away.
However, I discovered another problem. If the Button doesn't have a Table parent, it doesn't update its own size correctly when its text changes.
I found a solution. Place the Button in a Container and add the Container to the Stage. Use your MoveToActions on the Container that wraps the Button, not the Button itself.

How can I align label of a button component

I have a button component on my scene. But when I set labelPlacement to left, it can't do that. How can I fix this?
From what I understand and have read about the labelPlacement property is that it works in conjunction with the use of an icon within the button, not to necessarily change the position of the text in relation to the button boundary.
Here is some text that documents this from the Adobe Website:
If you are using an icon with a Button instance, you can control the placement of the text label, relative to the icon, by setting the labelPlacement property using one of the constants from the ButtonLabelPlacement class (fl.controls.ButtonLabelPlacement). For more information on working with button icons, see Setting icons.
Source: http://www.adobe.com/devnet/flash/quickstart/button_component_as3.html
Additional sources: http://www.adobe.com/devnet/flash/quickstart/button_component_as3.html#articlecontentAdobe_numberedheader_6
However, a hackish way of moving the text to the left would be to add spaces to the right of the string. Currently, empty spaces at the start or end of the label are not auto trimmed. Here is an example of what I am talking about:
import fl.controls.Button;
var myButton:Button = new Button();
myButton.label = "Click me ";
addChild(myButton);
I tested the code shown above in Flash CC 2014 and the text looked like it was left aligned, when it really wasn't because of the additional spaces added to the end of label.
It is worth mentioning that I also experiemented with the textField property of the Button class to see if the autoSize or setTextFormat functionality could be used to left align the text, and those all failed.

TextField input not working

I am working on a class similar to the standard text field. I actually use the default TextField inside it. My only problem is that the textField does not work correctly. If I set it to textField.type = TextFieldType.INPUT, I can delete the text, but I can't enter new text. Also, the cursor is not being displayed. This is my Class (part of it): http://pastebin.com/LsgQjxpa
The skin is like this: http://pastebin.com/yDhEGHLm
I can't figure out what exactly I am doing wrong. I also have to mention that I am compiling for AIR Mobile and testing directly from Flash Builder
One problem appears to be that you have set the selectable property to false. This makes sense when type is TextFieldType.DYNAMIC. However, it's problematic when the type is TextFieldType.INPUT.
When you disable selection of the text, no cursor is displayed. I am able to still edit the text. However, since the cursor is not visible I cannot change it's position and the text gets added in front of any existing text.

ActionScript Setting Caret Position In Text Layout Framework

i'm attempting to simply set the caret position at the start of the text flow when it is first displayed, without having to click and activate the text to see the blinking caret.
googling returns that the solution is to do this:
textFlow.interactionManager = new EditManager(new UndoManager());
textFlow.interactionManager.setSelection(0, 0);
however, setSelection() is not a valid function of the selection or edit managers.
1061: Call to a possibly undefined
method setSelection through a
reference with static type
flashx.textLayout.edit:ISelectionManager.
figured it out. for anyone else who ever has to deal with the nightmare that is the text layout framework documentation, you can automatically position and display the blinking caret after the text is displayed by writing this:
textFlow.interactionManager.selectRange(0, 0);
textFlow.interactionManager.setFocus();