Scroll Help nifty Gui

First of all - what has happend to you? You sound different then the Andy from yesterday! Are you ok? :wink:



The scrollPanel control you are using assumes that the area you are scrolling (the first child) is using an absolute width and height. It just allows you to scroll over this area using the scrollbars.



You can use the setVerticalPos(float) method to position the scrollbar from java or you can use the showElementVertical(int) to position the scrollpanel in steps. The stepsize - which is the height of a single line in you case - should be specified with the stepSizeY="<line-height-in-px>" at the scrollPanel control.



If we assume your line height is 20 pixel you should set stepSizeY="20" and you can simply position the scrollbar from java using the showElementVertical(5) method and it will position at the 5th line.



Take a look at the intro.xml and the menuScrollPanel panel in the nifty-examples for an example.

Well, now it get's interessting :smiley:



Your latest xml looks like the picture I've attached here! To me this looks actual pretty good.



How does that look at your side?

What Nifty Version do you use?

Yeah so it looks ok - but its not functional, you append stuffto the label, it continues to append but the scrolling doeent connect to the label…meaning it doesnt work but it looks - alright.

after adding a line to the label you need to position to the last element on your own, because nifty don't know that. you simply call that method I have told you about after you've added a line and positon the scrollPanel to the last element so that it is visible…

The scrollPanel control you are using assumes that the area you are scrolling (the first child) is using an absolute width and height. It just allows you to scroll over this area using the scrollbars.


Did you read this? Its from the very first reply.

I'm sorry but the current implementation of the Scrollpanel control will not support changing the size of the scrolling region. It assumes that this area has a fixed width and height. You can't scroll around if the area - as in your case - is changing.

It would be nice to have this but it is currently not supported.

These are your choices:

a) give up on the feature
b) add a feature request in niftys feature request tracker at sf.net
c) take a look at the implementation of the scrollpanel control on your own which is not that hard and try to add the feature on your own
d) use a single vertical scrollbar, add a scrollbarnotify to it and each time you add a message resize the label, change the max value of the scrollbar on your own and reposition the scrollbar to the end

It won't work correctly. Just add enough text so that the text does use more space then your 220px. text added after the 220px will not show and you won't be able to scroll to it.

Aha - you are correct. Darn.



I have a funny feeling I wont be able to make the appropriate change - because I dont understand quite what needs to be done - still learning how to use the predefined controls in nifty gui. :frowning:



I will make a feature request - but assume it will be a fair bit of time before it gets looked at

I have created a feature request:



http://sourceforge.net/tracker/?func=detail&aid=3034175&group_id=223898&atid=1059825

what about using the listbox control for your chat history?



you can add elements there:


LabelCreator createLabel = new LabelCreator("show off element add");
createLabel.setStyle("nifty-listbox-item");

listbox.addElement(createLabel.create(...



the controls demo in the nifty-examples project shows how to use this in details and it already contains code how to populate the listbox.

you are a bit unlucky with Nifty aren't you :wink:



I'm sorry, I should have told you before that there are two ways to add new listbox items to a listbox:



a) the addItem(String) method to add a simple string

b) the addElement(Element) method to add any element, like images or so to the listbox



in your case method a) would be easier I suppose. can you try this one instead?



in case of method b) there is a little tricky thing you need to know that is not obvious. any element you add to the listbox needs to be a parent of a special element with the listbox id and "Data" appended. In your case you should create the label with the parent (last parameter of createLabel.create call) "chatfieldData". if you look closely to the example then it is using this cumbersome way correctly.



so and now you really can be angry and bitch about nifty! this time I'll understand you!  because this really sucks bad :smiley: I know this must be changed but hasn't been a top priority yet.



I'm sorry about that specific method  :(



edit: "A listener was NOT BEST PLEASED about the message I just gave it." <-- was this the error message you received or did you forget to append a stacktrace or so? I can't remember that message and I couldn't find it o_O

Haha ok it was something somebody else in my project committed which was making that sysout!



So i tried chatfield.addItem(msgreceived) however i get a nasty set of null pointers:




java.lang.NullPointerException
        at de.lessvoid.nifty.controls.dynamic.attributes.ControlAttributes.buildControl(ControlAttributes.java:333)
        at de.lessvoid.nifty.controls.dynamic.attributes.ControlAttributes.createLabel(ControlAttributes.java:286)
        at de.lessvoid.nifty.controls.dynamic.LabelCreator.access$000(LabelCreator.java:10)
        at de.lessvoid.nifty.controls.dynamic.LabelCreator$1.createControl(LabelCreator.java:27)
        at de.lessvoid.nifty.Nifty$ControlToAdd.createControl(Nifty.java:734)
        at de.lessvoid.nifty.Nifty.addControlsWithoutStartScreen(Nifty.java:274)
        at de.lessvoid.nifty.controls.dynamic.LabelCreator.create(LabelCreator.java:30)
        at de.lessvoid.nifty.controls.listbox.controller.ListBoxControl.addItem(ListBoxControl.java:172)
        at org.whiterush.networking.ClientNetworkHandler.messageReceived(ClientNetworkHandler.java:93)
        at snow.network.api.client.connections.ClientConnection._acceptData(ClientConnection.java:113)
        at snow.network.api.client.connections.ClientConnection.run(ClientConnection.java:64)
        at java.lang.Thread.run(Thread.java:619)
java.lang.NullPointerException
        at de.lessvoid.nifty.controls.dynamic.attributes.ControlAttributes.buildControl(ControlAttributes.java:333)
        at de.lessvoid.nifty.controls.dynamic.attributes.ControlAttributes.createLabel(ControlAttributes.java:286)
        at de.lessvoid.nifty.controls.dynamic.LabelCreator.access$000(LabelCreator.java:10)
        at de.lessvoid.nifty.controls.dynamic.LabelCreator$1.createControl(LabelCreator.java:27)
        at de.lessvoid.nifty.Nifty$ControlToAdd.createControl(Nifty.java:734)
        at de.lessvoid.nifty.Nifty.addControls(Nifty.java:257)
        at de.lessvoid.nifty.Nifty.handleDynamicElements(Nifty.java:216)
        at de.lessvoid.nifty.Nifty.render(Nifty.java:177)
        at com.jme3.niftygui.NiftyJmeDisplay.postQueue(NiftyJmeDisplay.java:99)
        at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:541)
        at com.jme3.renderer.RenderManager.render(RenderManager.java:562)
        at org.whiterush.main.WhiteRushBase.update(WhiteRushBase.java:322)
        at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:112)
        at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:162)
        at java.lang.Thread.run(Thread.java:619)
25-Jul-2010 18:44:25 com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.util.ConcurrentModificationException
        at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
        at java.util.AbstractList$Itr.next(AbstractList.java:343)
        at de.lessvoid.nifty.Nifty.addControls(Nifty.java:255)
        at de.lessvoid.nifty.Nifty.handleDynamicElements(Nifty.java:216)
        at de.lessvoid.nifty.Nifty.render(Nifty.java:177)
        at com.jme3.niftygui.NiftyJmeDisplay.postQueue(NiftyJmeDisplay.java:99)
        at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:541)
        at com.jme3.renderer.RenderManager.render(RenderManager.java:562)
        at org.whiterush.main.WhiteRushBase.update(WhiteRushBase.java:322)
        at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:112)
        at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:162)
        at java.lang.Thread.run(Thread.java:619)

Ahh right didnt realise that was important…



so now it doesnt error - but it also doesnt append any new strings to the list box?

dude, then you need to check if you are missing something else I suppose. It works in the controls example and it worked in a test I've done for you yesterday. Maybe take another look at the example?

The test isnt doing exactly what im doing though - its dynamically creating a listbox and appending to it.



I want to define the listbox in xml and append to it …



Ill have a further play but not finding this easy.

dude, I seriously think you are making fun of me!



let's take that step my step. I've attached a screenshot of the controls example. the example uses two listboxes. one that is static and created in the xml and another that is dynamically created from java. just to show people how to use both mechanism.



then there is the ControlsDemoStartScreen and it's bind() method. at line 158 it says:


// select first item on the static listbox too
ListBoxControl listBoxStatic = screen.findControl("listBoxStatic", ListBoxControl.class);
listBoxStatic.changeSelection(0);



when you just add a one line:

// select first item on the static listbox too
ListBoxControl listBoxStatic = screen.findControl("listBoxStatic", ListBoxControl.class);

// add a new item to the listbox
listBoxStatic.addItem("a new item");



you get the result as shown in the screenshot!

what's the problem? <-- I wanted to write f*cking somewhere in there but I don't want to be rude


Ahh i see - this is different to the TestNifty test bundled within jME.



Cheers.