[nifty] FIXED: Getting the Chat Area example to work

Hello. I am working with the tutorial found here:



http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=ChatArea_Example



Sadly, I have most of it working. The only thing which is not working is that the text will continue to stack up, but I cannot scroll down to see new text.

The following methods were not found when I implemented:



[java] public void setAutoScroll(AutoScroll auto) {

scrollPanel.setAutoScroll(auto); //setAutoScroll() was not found

}



public AutoScroll getAutoScroll() {

return scrollPanel.getAutoScroll(); //getAutoScroll() was not found

}[/java]



and



[java]textArea.setHeight(textArea.getRenderer(TextRenderer.class).getTextHeight()); //setHeight() was not found[/java]



So, as I was saying, the scroll panel is not scrolling at all. I am curious if this is a known issue?



Thanks!

To add to my previous problems, I am having a crashing problem with this chat area.



When I call the sendMessage() method and do this:



[java] String t = “/n”+“00000000000000000000000000 0000000000000000000000000000000000”;

chatArea.append(t);[/java]



I get the following crash:



[java]Dec 11, 2010 6:55:34 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[Thread-2,5,main]

java.lang.OutOfMemoryError: Java heap space

at java.lang.AbstractStringBuilder.(AbstractStringBuilder.java:45)

at java.lang.StringBuffer.(StringBuffer.java:79)

at de.lessvoid.nifty.elements.tools.TextBreak.processWords(TextBreak.java:37)

at de.lessvoid.nifty.elements.tools.TextBreak.split(TextBreak.java:24)

at de.lessvoid.nifty.elements.render.TextRenderer.bla(TextRenderer.java:394)

at de.lessvoid.nifty.elements.render.TextRenderer.setWidthConstraint(TextRenderer.java:407)

at de.lessvoid.nifty.elements.Element.processLayoutInternal(Element.java:563)

at de.lessvoid.nifty.elements.Element.processL(Element.java:569)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.layoutElements(Element.java:597)

at de.lessvoid.nifty.screen.Screen.layoutLayers(Screen.java:185)

at GUI.ChatAreaController.setText(ChatAreaController.java:66)

at GUI.ChatAreaController.append(ChatAreaController.java:58)

at GUI.Side_Menu.receiveMessage(Side_Menu.java:88)

at network.client$ChatResponder.messageReceived(client.java:67)

at com.jme3.network.connection.Connection.fireMessageReceived(Connection.java:353)

at com.jme3.network.connection.TCPConnection.read(TCPConnection.java:204)

at com.jme3.network.connection.Connection.run(Connection.java:124)

at com.jme3.network.connection.ConnectionRunnable.run(ConnectionRunnable.java:77)

at java.lang.Thread.run(Thread.java:619)

Dec 11, 2010 6:55:41 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.OutOfMemoryError: Java heap space

at java.util.Arrays.copyOfRange(Arrays.java:3209)

at java.lang.String.(String.java:216)

at java.lang.StringBuffer.toString(StringBuffer.java:585)

at de.lessvoid.nifty.elements.tools.TextBreak.processWords(TextBreak.java:47)

at de.lessvoid.nifty.elements.tools.TextBreak.split(TextBreak.java:24)

at de.lessvoid.nifty.elements.render.TextRenderer.bla(TextRenderer.java:394)

at de.lessvoid.nifty.elements.render.TextRenderer.setWidthConstraint(TextRenderer.java:407)

at de.lessvoid.nifty.elements.Element.processLayoutInternal(Element.java:563)

at de.lessvoid.nifty.elements.Element.processL(Element.java:569)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.processL(Element.java:583)

at de.lessvoid.nifty.elements.Element.layoutElements(Element.java:597)

at de.lessvoid.nifty.screen.Screen.layoutLayers(Screen.java:185)

at de.lessvoid.nifty.controls.textfield.controller.TextFieldControl.updateCursor(TextFieldControl.java:222)

at de.lessvoid.nifty.controls.textfield.controller.TextFieldControl.inputEvent(TextFieldControl.java:181)

at de.lessvoid.nifty.controls.NiftyInputControl.keyEvent(NiftyInputControl.java:38)

at de.lessvoid.nifty.elements.Element.keyEvent(Element.java:1460)

at de.lessvoid.nifty.controls.FocusHandler.keyEvent(FocusHandler.java:211)

at de.lessvoid.nifty.screen.Screen.keyEvent(Screen.java:332)

at de.lessvoid.nifty.Nifty.processKeyboardEvent(Nifty.java:202)

at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:123)

at de.lessvoid.nifty.Nifty.render(Nifty.java:163)

at com.jme3.niftygui.NiftyJmeDisplay.postQueue(NiftyJmeDisplay.java:136)

at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:660)

at com.jme3.renderer.RenderManager.render(RenderManager.java:687)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:216)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)[/java]



Now… when I remove the " " (space) from the above screen, this crash doesnt happen. Note that this is a consistent crash and happens every time.



So, I am curious what anyone knows about this. I have tried to track it down to inside the code by putting String outputs along the execution path, and it ends right before [java]screen.layoutLayers();[/java]



but that doesn’t necessarily mean thats the location of the problem, just where the heap overflows.

Also note my above scrolling problem still exists.



Thanks for any help!

Hmm, there must be something missing in the trunk then (or are you using one of the jars?).

I created that tutorial and it still works in my workspace, so I’ll look through it and see if something didn’t get committed properly.



Edit: I’ve looked in the trunk and the needed functionality seems to all be there.

Make sure you have the latest trunk (although this was committed some time ago, 2010-08-19) and let me know if you still have problems with it.

Well, in regards to my first post with AutoScroll, here is the ScrollPanel.java which is being sourced in.

Is this an outdated version?



[java]package de.lessvoid.nifty.controls.scrollpanel;



import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.controls.Controller;

import de.lessvoid.nifty.controls.scrollbar.controller.HorizontalScrollbarControl;

import de.lessvoid.nifty.controls.scrollbar.controller.VerticalScrollbarControl;

import de.lessvoid.nifty.controls.scrollpanel.ScrollPanel.VerticalAlign;

import de.lessvoid.nifty.elements.ControllerEventListener;

import de.lessvoid.nifty.elements.Element;

import de.lessvoid.nifty.input.NiftyInputEvent;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.xml.xpp3.Attributes;

import java.util.Properties;



public class ScrollPanel implements Controller {



public enum VerticalAlign {



top, center, bottom;



private VerticalAlign() {

//compiled code

throw new RuntimeException(“Compiled Code”);

}

}

private Nifty nifty;

private Screen screen;

private Element element;

private boolean verticalScrollbar;

private boolean horizontalScrollbar;

private String childRootId;

private Element childRootElement;

private float stepSizeX;

private float stepSizeY;

private HorizontalScrollbarControl horizontalS;

private VerticalScrollbarControl verticalS;



public ScrollPanel() {

//compiled code

throw new RuntimeException(“Compiled Code”);

}



public void bind(Nifty niftyParam, Screen screenParam, Element elementParam, Properties parameter, ControllerEventListener listener, Attributes controlDefinitionAttributes) {

//compiled code

throw new RuntimeException(“Compiled Code”);

}



public boolean inputEvent(NiftyInputEvent inputEvent) {

//compiled code

throw new RuntimeException(“Compiled Code”);

}



public void onFocus(boolean getFocus) {

//compiled code

throw new RuntimeException(“Compiled Code”);

}



public void onStartScreen() {

//compiled code

throw new RuntimeException(“Compiled Code”);

}



public void initializeScrollPanel(Screen screen, float stepSizeX, float stepSizeY) {

//compiled code

throw new RuntimeException(“Compiled Code”);

}



public void setVerticalPos(float yPos) {

//compiled code

throw new RuntimeException(“Compiled Code”);

}



public void showElementVertical(int elemCount) {

//compiled code

throw new RuntimeException(“Compiled Code”);

}



public void showElementVertical(int elemCount, VerticalAlign valign) {

//compiled code

throw new RuntimeException(“Compiled Code”);

}

}

[/java]



Notice there is nothing in there to do with AutoScroll, as in getAutoScroll() or setAutoScroll() as is required per the tutorial.

Yes, that’s not the version in the current trunk, that must be from before 2010-08-19.

If you’re using the SVN version, try to update and see if you get the latest version.

I’m not sure in what jar-release this change was included.

Sorry. I just have the Nifty version found within the JME3 trunk, which is version 1.2



How would I go about updating to the latest version? I just did an update within JMP for all latest update, and I am still stuck with version 1.2

Eggsworth said:
Sorry. I just have the Nifty version found within the JME3 trunk, which is version 1.2

How would I go about updating to the latest version? I just did an update within JMP for all latest update, and I am still stuck with version 1.2
Nifty 1.3 is still a development version and not officially released yet, hence it's not part of the jMP update. Get the bleeding-edge Nifty release from the project's SVN:
http://sourceforge.net/projects/nifty-gui/

Ok.



I have isolated the problem. This ScrollPanel is located inside the nifty-default-controls jar file. The current JME is set to version 1.2, while this AutoScroll stuff is located in the 1.3 development version.



Since I am using the JME .jar libraries which are supplied with the JMP Alpha-3, it is difficult to switch in this new 1.2 version because of jar file dependencies.



So, hopefully version 1.3 of nifty makes its way into the nightly builds soon :slight_smile:





FIXED:

What I thought were .jar file dependencies was actually a missing .jar file.

Once I included

Nifty version 1.3:

default controls

and style black



I also needed to add

xmlpull-xpp3-1.1.4c.jar

which was the missing piece.



Now everything is working perfectly!



Thanks for the help everyone.

Glad you got it to work! :slight_smile: