Unable to access control inside ScrollPanel

I’m making a chat window for a multiplayer game I’m working on. The output area consists of a Scroll Panel with a Label child control, where text is to be written to. I’m using a custom chat controller object to handle receiving text and outputting it. In the bind method I have the following lines:

[java]textArea = screen.findElementByName(“output_area”);
scrollPanel = screen.findNiftyControl(“scroll_panel”, ScrollPanel.class);[/java]

Where [java]“output_area”[/java] and [java]“scroll_panel”[/java] are the IDs for the label and scroll panel, respectively. For completeness sake, here’s the function where I set the text:

[java]
public void setText(String text) {
textArea.getRenderer(TextRenderer.class).setText(text);
screen.layoutLayers();
textArea.setHeight(textArea.getRenderer(TextRenderer.class).getTextHeight());
}
[/java]

This is actually very similar to the code in one of the tutorials on the Nifty site. Whenever I run the game and test the output, however, the font looks awful, nothing like the font that appears on other labels. At first we thought it was just some weird font issue, but I think I’ve found the problem.

While trying to adjust the label so that it doesn’t stretch to the very edges of the scroll bar, I noticed that changing the width in XML made no difference to the text that was output. But, when I adjusted the width of the scroll panel, the text moved with it. I’ve concluded that our issue is that, for some reason, the text is being written to the scroll panel instead of its label child.

Am I wrong in thinking this? Looking at the code, I can’t see how this would be the case, but it would explain our issue with both the font and the fact that nothing happens to the text when we resize the label.

Another reason I suspect this is because my label uses the textVAlign and textHAlign to position the text in the bottom left corner of the label, which doesn’t happen.

1 Like

I been seeing similar issues with all my ScrollPanel controls since I switched from jME3 RC2 to 3.0Stable. I haven’t figured out what’s going on yet. If there’s some way to correct or work around this issue, I’m interested in hearing about it.

My issue has been successfully worked around. Maybe the same workaround will work for you!

See this thread for details.

1 Like