Welcome, Guest. Please login or register.
Did you miss your activation email?
September 08, 2010, 02:53:51 am
advanced search




Pages: 1 [2]
  Print  
Author Topic: Scroll Help nifty Gui  (Read 399 times)
void256
Jr. Member
**
Offline Offline

Posts: 74



View Profile WWW
« Reply #15 on: July 25, 2010, 08:46:10 am »

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.
Logged
renegadeandy
Full Member
***
Offline Offline

Posts: 292


View Profile
« Reply #16 on: July 25, 2010, 09:11:29 am »

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. Sad

I will make a feature request - but assume it will be a fair bit of time before it gets looked at
Logged
renegadeandy
Full Member
***
Offline Offline

Posts: 292


View Profile
« Reply #17 on: July 25, 2010, 09:16:11 am »

I have created a feature request:

http://sourceforge.net/tracker/?func=detail&aid=3034175&group_id=223898&atid=1059825
Logged
void256
Jr. Member
**
Offline Offline

Posts: 74



View Profile WWW
« Reply #18 on: July 25, 2010, 04:47:32 pm »

what about using the listbox control for your chat history?

you can add elements there:

Code:
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.
Logged
renegadeandy
Full Member
***
Offline Offline

Posts: 292


View Profile
« Reply #19 on: July 26, 2010, 12:03:48 am »

Hmm that may just be ideal!

Am trying but not quite got it working, so when a new chat message is received I run the following code:

Code:
   System.out.println("CHAT MESSAGE RECEIVED:" + msgreceived);
            // you can add elements too :)
            LabelCreator createLabel = new LabelCreator(msgreceived);
            createLabel.setStyle("nifty-listbox-item");

            ControlEffectAttributes effectParam = new ControlEffectAttributes();
            effectParam.setName("updateScrollpanelPositionToDisplayElement");
            effectParam.setAttribute("target", "listBoxDynamic");
            effectParam.setAttribute("oneShot", "true");
            createLabel.addEffectsOnCustom(effectParam);
            Element listBoxDataParent = SnowReference.getScreen().findElementByName("chatfieldpanel");
            chatField.addElement(createLabel.create(SnowReference.getNifty(), SnowReference.getScreen(), listBoxDataParent));

And now the relevant section from my XML file looks like this

Code:
        <panel id="ae" childLayout="horizontal" height="100%">
              <label id="af" text="Chat:" align="left" width="25%" textHAlign="left"/>
            <control id="chatfield" name="listBox" horizontal="false" width="*" height="100%" childLayout="vertical" visibleToMouse="true">
              <panel id="chatfieldpanel" width="75%" childLayout="vertical" visibleToMouse="true">
                <label text="Static Item I" style="my-listbox-item-style" />
                <label text="Fo Shizzle" style="my-listbox-item-style" />
                <label text="Static Item III" style="my-listbox-item-style" />
                <label text="Static Items ftw" style="my-listbox-item-style" />
              </panel>
            </control>
          </panel>

When i run the code i get this funny system out message :

CHAT MESSAGE RECEIVED:21:lol
A listener was NOT BEST PLEASED about the message I just gave it.
Logged
void256
Jr. Member
**
Offline Offline

Posts: 74



View Profile WWW
« Reply #20 on: July 26, 2010, 12:29:21 am »

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 Cheesy I know this must be changed but hasn't been a top priority yet.

I'm sorry about that specific method  sad

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
« Last Edit: July 26, 2010, 12:31:25 am by void256 » Logged
renegadeandy
Full Member
***
Offline Offline

Posts: 292


View Profile
« Reply #21 on: July 26, 2010, 12:56:21 am »

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:

Code:

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)
Logged
void256
Jr. Member
**
Offline Offline

Posts: 74



View Profile WWW
« Reply #22 on: July 26, 2010, 04:46:01 am »

Well, you need to copy everything. Here is the listBox from the nifty-examples project:

Code:
<control id="listBoxStatic" name="listBox" horizontal="false" width="*" height="100%" childLayout="vertical" visibleToMouse="true">
  <panel id="listBoxStaticData" width="100%" childLayout="vertical" visibleToMouse="true">
    <label text="Static Item I" style="my-listbox-item-style" />
    <label text="Fo Shizzle" style="my-listbox-item-style" />
    <label text="Static Item III" style="my-listbox-item-style" />
    <label text="Static Items ftw" style="my-listbox-item-style" />
  </panel>
</control>

You see the panel with the id "listBoxStaticData"? You'll need this one too. EDIT: It's just an element with the same id as the control with "Data" appended.
Logged
renegadeandy
Full Member
***
Offline Offline

Posts: 292


View Profile
« Reply #23 on: July 26, 2010, 06:28:02 am »

Ahh right didnt realise that was important...

so now it doesnt error - but it also doesnt append any new strings to the list box?
Logged
void256
Jr. Member
**
Offline Offline

Posts: 74



View Profile WWW
« Reply #24 on: July 26, 2010, 03:40:37 pm »

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?
Logged
renegadeandy
Full Member
***
Offline Offline

Posts: 292


View Profile
« Reply #25 on: July 27, 2010, 01:58:04 am »

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.
Logged
void256
Jr. Member
**
Offline Offline

Posts: 74



View Profile WWW
« Reply #26 on: July 27, 2010, 03:17:06 am »

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:

Code:
// 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:

Code:
// 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


Logged
renegadeandy
Full Member
***
Offline Offline

Posts: 292


View Profile
« Reply #27 on: July 27, 2010, 03:47:04 am »

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

Cheers.
Logged
Tags:
Pages: 1 [2]
  Print  
 
Jump to: