From 0 to 60 in?

[java]pbar.setLocalTranslation(0, 0, 0);[/java]

Ahah…

First, since pbar is in a container then setting it’s local translation will do nothing because the container will be moving it again to some position local to itself.

Second, Lemur grows components down. The location of a component will be its upper left corner… so the fact that your block container is still at 0,0,0 means it’s extending off the bottom of the screen.

Sorry for the confusion. I should have mentioned that earlier.

Add block.setLocalTranslation(100, 100, 0);

…and see if the panel shows up.

I always expect people to understand that a post with some lines of code doesn’t reflect all the tests and tryouts anyone has done. I should explain better, be more detailed.

So…

The code above was one of the last tests I did. I started with only the bare essential. the pbar and only this, then I use a container. Then I tried pbar with a local translation, then the container with a local translation. Then I used another container with the prior progressbar tests, the very first one in the previous posts, then I mixed other stuff together. I reverted the changes, commented and uncommented and eventually came back to that version above.

In short, I spent north of 5 hours trying different things, reading on the lib, the “stacking modes”, comparing code found in demo with my own tests. I also took breaks during that time because my brain is threatening to “go on effing strike if it goes on much more like this”. I preferred if it went on working, mind you. My brain is the sexiest thing attached to my body, so, yeah. I love it when it works and would love to keep it that way. :stuck_out_tongue:

Now. Could you please give me a working example of a progress bar if that’s not too much to ask?

I’m sorry if I’m sounding a little angry, but I have spent close to an entire week on this and haven’t gotten very far and starting to consider rolling my own Gui lib and I know if I do this, it’ll be extremely painful. I don’t like pain.

Sorry you have been having so much trouble with what should be a simple thing. Hopefully you will figure out what I forgot to say.

Here is a working example… I started it as a Gem and then haven’t committed it… but here is a working example of all methods discussed so far:

[java]
package gems;

import com.jme3.app.SimpleApplication;
import com.jme3.app.StatsAppState;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.FillMode;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.Panel;
import com.simsilica.lemur.ProgressBar;
import com.simsilica.lemur.component.DynamicInsetsComponent;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;

/**

  • The main application for demonstrating some Lemur layout

  • tricks.

  • @author pspeed
    */
    public class LayoutDemo extends SimpleApplication {

    private float percent = 0.5f;
    private float delta = 0.1f;

    private Label valueDisplay;
    private Panel progressA;
    private Panel progressB;
    private ProgressBar progressC;

    public static void main(String[] args) {
    LayoutDemo app = new LayoutDemo();
    app.start();
    }

    public LayoutDemo() {
    super(new StatsAppState());
    }

    @Override
    public void simpleInitApp() {

    GuiGlobals.initialize(this);
    
    valueDisplay = new Label("Value:" + (int)(percent * 100) + "%");
    valueDisplay.setLocalTranslation(0, cam.getHeight(), 0);
    guiNode.attachChild(valueDisplay);
    
    // We'll make one root container to hold all of our progress
    // bars and their labels.  This will be a spring grid layout
    // in row-major form.  If we add children without specifying contraints
    // then each one will get a new row.
    Container root = new Container();
    root.setBackground(new QuadBackgroundComponent(new ColorRGBA(0, 0, 0.3f, 1), 5, 5));                
    guiNode.attachChild(root);
    
    // First we'll fool the layout into keeping our progress bar
    // constrained but still letting us change its x size manually.
    // By using FillMode.None for the x-axis, components will be laid
    // out purely by their own preferred size.
    Container first = new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.Even, FillMode.None));
    first.setBackground(new QuadBackgroundComponent(ColorRGBA.Red, 2, 2));                
    progressA = first.addChild(new Panel(0, 0, ColorRGBA.Green));
    
    // Containers will resize themselves to preferred size when 
    // first initialized... even if a size has been set.  Here we
    // override the container's preferred size with our own and
    // it will never recalculate it until cleared.
    first.setPreferredSize(new Vector3f(204, 20, 0));
    
    root.addChild(new Label("Test 1, Spring Layout"));
    root.addChild(first);
    
    // The problem with Test 1 is that even though the y-axis
    // is constrained, it is up to us to make sure we don't set the
    // x-size bigger than the container will hold.
    //
    // Also notice above this included having to keep track of our
    // background margin in our sizing and so on.  (204 container size
    // versus 200)
    
    // In this next approach, we will use dynamic insets to make the
    // SpringGridLayout let us have a different sized child without
    // ever violating the layout constraints.  Other than that, it's
    // really no different, though.  Width still has to be calculated
    // relative to the parent and so on... the only difference is that
    // if we get it too big then the container will grow to fit. 
    Container second = new Container();
    second.setBackground(new QuadBackgroundComponent(ColorRGBA.Red, 2, 2));                
    progressB = second.addChild(new Panel(0, 16, ColorRGBA.Yellow));
    progressB.setInsetsComponent(new DynamicInsetsComponent(0, 0, 0, 1.0f));
    
    // Here we let the "second" container pick up the size from the parent layout.
    
    root.addChild(new Label("Test 2, Dynamic Insets"));
    root.addChild(second);
    
    
    root.addChild(new Label("Test 3, Built In"));
    progressC = root.addChild(new ProgressBar());
    
    // Set the location of the root container based on its size
    Vector3f size = root.getPreferredSize();
    root.setLocalTranslation((int)(cam.getWidth() * 0.5f - size.x * 0.5f), 
                             (int)(cam.getHeight() * 0.5f + size.y * 0.5f), 
                             0);              
    

    }

    @Override
    public void simpleUpdate(float tpf) {

    percent += delta * tpf;
    if( percent >= 1.0 ) {
        percent = 1.0f;
        delta *= -1;
        progressC.setMessage("Down...");
    } else if( percent <= 0.0 ) {
        percent = 0.0f;
        delta *= -1;
        progressC.setMessage("Up...");
    }
    
    valueDisplay.setText("Value:" + (int)(percent * 100) + "%");
    
    progressA.setPreferredSize(new Vector3f(percent * 200, 20, 0));
    progressB.setPreferredSize(new Vector3f(percent * 200, 16, 0));
    progressC.setProgressPercent(percent);
    

    }

    @Override
    public void simpleRender(RenderManager rm) {
    }
    }
    [/java]

The example works fine except at the point where every extraneous components have been removed. At that point I should, technically, only have a working progress bar, but nope. Nothing shows up.

Comment lines 61-103, 131 and 132. Then SHIFT F6.

You only get the top left percentage counter and nothing else.


In view of this I have no other choice, but to go the only way that will really satisfy me. I’ll make SimpleGUI so that way I won’t rage about anyone’s library, whether because I find them too buggy or esoteric.

Thanks for the time you’ve spent with me on this Paul. It’s been appreciated. Lemur and me, we won’t ever be friends. :slight_smile:

Here’s the version with those lines commented out and setting the preferred size so that the progress bar doesn’t end up as 0,0,0 in size:

[java]
/*

  • $Id$
  • Copyright © 2013-2013 jMonkeyEngine
  • All rights reserved.
  • Redistribution and use in source and binary forms, with or without
  • modification, are permitted provided that the following conditions are
  • met:
    • Redistributions of source code must retain the above copyright
  • notice, this list of conditions and the following disclaimer.
    • Redistributions in binary form must reproduce the above copyright
  • notice, this list of conditions and the following disclaimer in the
  • documentation and/or other materials provided with the distribution.
    • Neither the name of ‘jMonkeyEngine’ nor the names of its contributors
  • may be used to endorse or promote products derived from this software
  • without specific prior written permission.
  • THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  • “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  • TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  • PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  • CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  • EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  • PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  • PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  • LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  • NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  • SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */
    package gems;

import com.jme3.app.SimpleApplication;
import com.jme3.app.StatsAppState;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.FillMode;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.Panel;
import com.simsilica.lemur.ProgressBar;
import com.simsilica.lemur.component.DynamicInsetsComponent;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;

/**

  • The main application for demonstrating some Lemur layout

  • tricks.

  • @author pspeed
    */
    public class LayoutDemo extends SimpleApplication {

    private float percent = 0.5f;
    private float delta = 0.1f;

    private Label valueDisplay;
    private Panel progressA;
    private Panel progressB;
    private ProgressBar progressC;

    public static void main(String[] args) {
    LayoutDemo app = new LayoutDemo();
    app.start();
    }

    public LayoutDemo() {
    super(new StatsAppState());
    }

    @Override
    public void simpleInitApp() {

    GuiGlobals.initialize(this);
    
    valueDisplay = new Label("Value:" + (int)(percent * 100) + "%");
    valueDisplay.setLocalTranslation(0, cam.getHeight(), 0);
    guiNode.attachChild(valueDisplay);
    
    // We'll make one root container to hold all of our progress
    // bars and their labels.  This will be a spring grid layout
    // in row-major form.  If we add children without specifying contraints
    // then each one will get a new row.
    Container root = new Container();
    root.setBackground(new QuadBackgroundComponent(new ColorRGBA(0, 0, 0.3f, 1), 5, 5));                
    guiNode.attachChild(root);
    

/*
// First we’ll fool the layout into keeping our progress bar
// constrained but still letting us change its x size manually.
// By using FillMode.None for the x-axis, components will be laid
// out purely by their own preferred size.
Container first = new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.Even, FillMode.None));
first.setBackground(new QuadBackgroundComponent(ColorRGBA.Red, 2, 2));
progressA = first.addChild(new Panel(0, 0, ColorRGBA.Green));

    // Containers will resize themselves to preferred size when 
    // first initialized... even if a size has been set.  Here we
    // override the container's preferred size with our own and
    // it will never recalculate it until cleared.
    first.setPreferredSize(new Vector3f(204, 20, 0));
    
    root.addChild(new Label("Test 1, Spring Layout"));
    root.addChild(first);

    // The problem with Test 1 is that even though the y-axis
    // is constrained, it is up to us to make sure we don't set the
    // x-size bigger than the container will hold.
    //
    // Also notice above this included having to keep track of our
    // background margin in our sizing and so on.  (204 container size
    // versus 200)

    // In this next approach, we will use dynamic insets to make the
    // SpringGridLayout let us have a different sized child without
    // ever violating the layout constraints.  Other than that, it's
    // really no different, though.  Width still has to be calculated
    // relative to the parent and so on... the only difference is that
    // if we get it too big then the container will grow to fit. 
    Container second = new Container();
    second.setBackground(new QuadBackgroundComponent(ColorRGBA.Red, 2, 2));                
    progressB = second.addChild(new Panel(0, 16, ColorRGBA.Yellow));
    progressB.setInsetsComponent(new DynamicInsetsComponent(0, 0, 0, 1.0f));
    
    // Here we let the "second" container pick up the size from the parent layout.
    
    root.addChild(new Label("Test 2, Dynamic Insets"));
    root.addChild(second);

    root.addChild(new Label("Test 3, Built In"));

*/
progressC = root.addChild(new ProgressBar());
progressC.setPreferredSize(new Vector3f(200, 20, 0));

    // Set the location of the root container based on its size
    Vector3f size = root.getPreferredSize();
    root.setLocalTranslation((int)(cam.getWidth() * 0.5f - size.x * 0.5f), 
                             (int)(cam.getHeight() * 0.5f + size.y * 0.5f), 
                             0);              
}

@Override
public void simpleUpdate(float tpf) {

    percent += delta * tpf;
    if( percent >= 1.0 ) {
        percent = 1.0f;
        delta *= -1;
        progressC.setMessage("Down...");
    } else if( percent <= 0.0 ) {
        percent = 0.0f;
        delta *= -1;
        progressC.setMessage("Up...");
    }
    
    valueDisplay.setText("Value:" + (int)(percent * 100) + "%");
    
    //progressA.setPreferredSize(new Vector3f(percent * 200, 20, 0));
    //progressB.setPreferredSize(new Vector3f(percent * 200, 16, 0));
    progressC.setProgressPercent(percent);
}

@Override
public void simpleRender(RenderManager rm) {
}

}
[/java]

Sorry you were having so much trouble with this. It really shouldn’t have been this difficult. :-/

If you roll your own GUI you might still consider using the picking stuff from Lemur. It can be used without the other stuff.

And for those coming in late, here is an even simpler version that displays the progress bar without a container or anything:
[java]
package gems;

import com.jme3.app.SimpleApplication;
import com.jme3.app.StatsAppState;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.FillMode;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.Panel;
import com.simsilica.lemur.ProgressBar;
import com.simsilica.lemur.component.DynamicInsetsComponent;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;

/**

  • The main application for demonstrating some Lemur layout

  • tricks.

  • @author pspeed
    */
    public class LayoutDemo extends SimpleApplication {

    private float percent = 0.5f;
    private float delta = 0.1f;

    private Label valueDisplay;
    private ProgressBar progressC;

    public static void main(String[] args) {
    LayoutDemo app = new LayoutDemo();
    app.start();
    }

    public LayoutDemo() {
    super(new StatsAppState());
    }

    @Override
    public void simpleInitApp() {

    GuiGlobals.initialize(this);
    
    valueDisplay = new Label("Value:" + (int)(percent * 100) + "%");
    valueDisplay.setLocalTranslation(0, cam.getHeight(), 0);
    guiNode.attachChild(valueDisplay);
    
    progressC = new ProgressBar();
    progressC.setPreferredSize(new Vector3f(200, 20, 0));
    progressC.setLocalTranslation((int)(cam.getWidth() * 0.5f - 100), 
                             (int)(cam.getHeight() * 0.5f + 10), 
                             0);
    guiNode.attachChild(progressC);              
    

    }

    @Override
    public void simpleUpdate(float tpf) {

    percent += delta * tpf;
    if( percent >= 1.0 ) {
        percent = 1.0f;
        delta *= -1;
        progressC.setMessage("Down...");
    } else if( percent <= 0.0 ) {
        percent = 0.0f;
        delta *= -1;
        progressC.setMessage("Up...");
    }
    
    valueDisplay.setText("Value:" + (int)(percent * 100) + "%");
    
    progressC.setProgressPercent(percent);
    

    }

    @Override
    public void simpleRender(RenderManager rm) {
    }
    }
    [/java]