Nifty Gui Chat builder / control word wrapping?

I’m using the java version to build a chat window but I can’t figure out how to get word wrapping to work in the chat area.



I’m building the chat window with the ChatBuilder class like this:

[java]

panel(new PanelBuilder(“panel_chat”) {{

childLayoutCenter();

alignCenter();

backgroundColor("#80808080");

height(“25%”);

width(“100%”);

ChatBuilder cb = new ChatBuilder(“ChatID”, 5) {{sendLabel(“Send”);}};

control(cb);

}});

[/java]



And when I add text to the chat window, I use this:

[java]

final Element chatPanel = nifty.getCurrentScreen().findElementByName(“panel_chat”);

final Chat chat = chatPanel.findNiftyControl(“ChatID”, Chat.class);

chat.receivedChatLine(“INSERT TEXT HERE”, null, “chat-control”);

[/java]



However, when the text that replaces “INSERT TEXT HERE” gets really long, it adds a scroll bar to the bottom that scrolls left and right. Is there a way to get the text in the main chat area to wrap?

Not sure in java but it’s possible to set wrap=“true” in xml.

@androlo said:
Not sure in java but it's possible to set wrap="true" in xml.


I've searched for it in either form, Java or XML, but looks like it doesn't work in the XML version either?
http://hub.jmonkeyengine.org/groups/gui/forum/topic/nifty-chat-control-not-wrapping/

It seems the text area uses a list box which doesn't support word wrapping... I'm not entirely sure how to redefine the panel in java to use a scroll pane instead, as the other user did above. I was hoping there was another solution I'm missing. :)

Well, unfortunately word wrapping is not supported in the chat control directly. The problem is that the chat control internally uses the Listbox. And the Listbox can only display elements of the same height. So you can’t have individual elements with different heights which you would end up when word wrapping would be supported.



What might work is when you would word-wrap your chat-lines by yourself and then kinda generate multiple single lines from your long lines. But that might or might not help you and it’s in general a bit cumbersome :confused:



Of course the real solution would be to allow individual rows in the ListBox to have different heights which would be really nice to have for other use cases as well. But this might take some time…

@void256

Please add word-wrapping for textfield and chat controls. :slight_smile:

My in game chat is based on this control http://hub.jmonkeyengine.org/groups/gui/forum/topic/textarea-with-line-wrapping-code/ which provide a textArea with line wrapping and which permit multiline text because it doesn’t based on listBox control.

The reason the default Nifty chat control uses the listbox is that this allows it to support icons in the chat lines. For instance, you can include the player avatar in each line of chat.

If you don’t need this, you could use the textarea for sure.

When I created the chat control for my personal use however, I needed that avatar in there. Since the current default control is based on my custom chat control, it also uses the same setup.