Reputation: 1407
In my Codename One app, while the app is sending a query, I want to show an InfiniteProgress
in the center and below it a centered Label which tells the user what is going on. So I created a container with BorderLayout
and added the infinite progress with constraint BorderLayout.CENTER
and a container with BorderLayout.SOUTH
constraint, which contains the label. The inner container layout is BorderLayout
with BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE
. I then just add the label with constraint BorderLayout.CENTER
, and this does center the label. However, when I try to change the text of the label to something longer, it gets cut. The problem can be demonstrated using the below simple example:
Form hi = new Form("Welcome", new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
Button button = new Button("Change text");
Label label = new Label("South");
button.addActionListener(event -> {
label.setText("A lot longer text");
});
hi.add(BorderLayout.CENTER, button);
Container container = new Container();
container.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
container.add(BorderLayout.CENTER, label);
hi.add(BorderLayout.SOUTH, container);
hi.show();
Now, when I click on the button to change the text of the label, you can see that the label does not show the whole text (see pictures).
Upvotes: 2
Views: 801
Reputation: 510
Add this line after you set the label text:
label.getParent().revalidate();
Upvotes: 2