(SOLVED)Progress bar change color

To chance the color of progress bar whem is full
I have to create a New style

1 Like

what ui library are you using?

1 Like

Lemur

1 Like

I mean… you haven’t actually asked a question so I’m having to guess what you mean. Are you asking “how do I change the color without using a style?” Or “how do I change the color using a style?”

I feel like maybe you haven’t found the javadoc yet so I will include a link for it:
http://jmonkeyengine-contributions.github.io/Lemur/javadoc/Lemur/

In this case, specifically:
http://jmonkeyengine-contributions.github.io/Lemur/javadoc/Lemur/com/simsilica/lemur/ProgressBar.html

…and very specifically:
http://jmonkeyengine-contributions.github.io/Lemur/javadoc/Lemur/com/simsilica/lemur/ProgressBar.html#getValueIndicator()

Or if you are trying to change it with a style, then the element ID will help you: ProgressBar (lemur 1.14.0 API)

3 Likes

By the way, I also moved your post to the proper category.

1 Like

i can´t change the colors

this is my code

import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;

import com.jme3.math.Vector3f;
import com.jme3.scene.Node;

import com.simsilica.lemur.Axis;
import com.simsilica.lemur.FillMode;
import com.simsilica.lemur.*;

import com.simsilica.lemur.component.SpringGridLayout;

/**
 *
 * @author Pedro Quesado
 */
public class CharactersStatusState extends BaseAppState {


     private Container loginPanel;
    private Container xp;
    private Container skill;

    @Override
    protected void initialize(Application app) {
        loginPanel = new Container();
        xp = new Container();
        skill = new Container();
        Container props = loginPanel.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.Last)));
        // props.setBackground(null);
        props.setPreferredSize(new Vector3f(200, 70, 0));

        props.addChild(new Label("HP"));
        ProgressBar HP = props.addChild(new ProgressBar(), 1); 
        HP.setProgressValue(100); //i want this with color red

        // HP.setBackground(new QuadBackgroundComponent(ColorRGBA.Red));
        props.addChild(new Label("MP")); //this is gonna be blue 
        ProgressBar MP = props.addChild(new ProgressBar(), 1);
        MP.setProgressValue(100);
        //  MP.setBackground(new QuadBackgroundComponent(ColorRGBA.Blue));
        props.addChild(new Label("DR"));
        ProgressBar DR = props.addChild(new ProgressBar(), 1);
        DR.setProgressValue(20);
        //    DR.setBackground(new QuadBackgroundComponent(ColorRGBA.Gray));
        Container pgrosse = xp.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.Last)));
        pgrosse.setPreferredSize(new Vector3f(1000, 20, 0));
        pgrosse.addChild(new Label("XP")); //this yellow
        ProgressBar XP = pgrosse.addChild(new ProgressBar(), 1);
        XP.setProgressValue(10);
        XP.setPreferredSize(new Vector3f(1000, 20, 0));
        //    XP.setBackground(new QuadBackgroundComponent(ColorRGBA.Brown));
        Container skillmenu = skill.addChild(new Container());
        skillmenu.setPreferredSize(new Vector3f(500, 50, 0));
        Container q = skillmenu.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.setPreferredSize(new Vector3f(50, 20, 0));
        
        float scale = 1.5f * getState(MainMenuState.class).getStandardScale();
        //  loginPanel.setLocalScale(scale);
        loginPanel.setBackground(null);
        Vector3f prefs = loginPanel.getPreferredSize().clone();
        prefs.x = Math.max(20, prefs.x);
        loginPanel.setPreferredSize(prefs.clone());

        // Now account for scaling
        prefs.multLocal(scale);

        int width = app.getCamera().getWidth();
        int height = app.getCamera().getHeight();

        loginPanel.setLocalTranslation(width * 0.10f - prefs.x * 0.10f, height * 0.10f - prefs.y * 0.0f, 10);
        xp.setLocalTranslation(width * 0.10f - prefs.x * 0.10f, height * 0.03f - prefs.y * 0.0f, 10);
        skill.setLocalTranslation(width * 0.23f - prefs.x * 0.0f, height * 0.080f - prefs.y * 0.0f, 10);
        //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected void cleanup(Application app) {
        //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected void onEnable() {
        Node root = ((Main) getApplication()).getGuiNode();
        root.attachChild(loginPanel);
        root.attachChild(xp);
        root.attachChild(skill);
///  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected void onDisable() {
        loginPanel.removeFromParent();
        xp.removeFromParent();
        skill.removeFromParent();//  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}
1 Like

Well, I don’t see where you are using any of the suggestions I gave you. I don’t even see any code that is trying to set the color. Is it the color of the whole progress bar you want to change? Just the value part?

You are going to have to learn to ask better questions or you aren’t going to get much more help.

1 Like

i triying make it work
sorry i forget to put the changes
this i try to do

 Label  ola = new Label("80/100");
    props.addChild(new Label("HP"));
            ProgressBar HP = props.addChild(new ProgressBar(ola.getElementId(),ola.getStyle()), 1);
            HP.getModel().setMaximum(300);
            HP.getModel().setMinimum(0);
             HP.getModel().setValue(100);
             ola.setBackground(new QuadBackgroundComponent(ColorRGBA.Red));

            HP.attachChild(ola);
1 Like

I don’t know what you are trying to do. You may need to draw a picture because your words aren’t able to explain it.

1 Like

i want put the HP in red
when i try elemet and style
the result it is

the HP is be red and is not

1 Like

Style only affects the elements when they are created. If you want the green bar to turn red then you have to grab it and change it’s background to a red background.

1 Like

when i change the background to red the background is red when is empty but when is full is green
i want is red when is full and when empty is no have color

    HP.setBackground(new QuadBackgroundComponent(ColorRGBA.Red));
   HP.setMessage("100/300");
   HP.getModel().setMaximum(300);
        HP.getModel().setMinimum(0);
        HP.getModel().setValue(20);
1 Like

Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
Do you want the bar red or the background red?
That’s all the times I’m going to repeat myself… I’m so done with this thread.

1 Like

i want the bar red
not the background

1 Like

From waaaaaay above that you seem to have skipped:

1 Like

thanks bro
help a lot

1 Like

Since the initial poster never provided an answer (facepalm). Here’s the answer:

ProgressBar bossHealth = new ProgressBar(new DefaultRangedValueModel(0, 9, 9));
bossHealth.setMessage(“Boss Health”);
bossHealth.getValueIndicator().setBackground(new QuadBackgroundComponent(ColorRGBA.Red));


The image shows a red bar as opposed to the default green bar. It’s it being used as a health bar for the boss instead of a progress bar.

1 Like