Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:15:31+00:00 2026-06-10T09:15:31+00:00

I have Four Panels being dynamically created from a single panel Mold each panel

  • 0

I have Four Panels being dynamically created from a single panel “Mold” each panel has different information on it being set from an array.
Problem is that when the information updates only the last panel in the set changes.

Example: there is a MovesLeft label that shows obviously the number of moves left. As the number goes down the number listed for that player should change, each player having their own panel. Currently only the last panel’s Moveleft Label changes and changes for any player who moves not just the last Player. So if Player 1 uses up all his moves it will show 0 on Player 4’s panel rather than on player 1’s Panel.

Question: is there a way for me to specify which of the four instances of the label I want to change so that the correct player’s info gets updated?

Panel Set up

    protected JComponent makeTextPanel(String text) {
    JPanel panel = new JPanel(false);
    //panel.add(filler);
    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    name = new JLabel(minirpg.MiniRPG.players.get(setupPlayerIndex).getName());
    c.insets = new Insets(5, 5, 5, 5);
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 2;
    panel.add(name, c);

    icon = new JLabel(MiniRPG.players.get(setupPlayerIndex).getIcon());
    c.gridx = 1;
    c.gridy = 2;
    panel.add(icon, c);

    lblClass = new JLabel("Class:");
    c.gridx = 1;
    c.gridy = 3;
    c.gridwidth = 1;
    panel.add(lblClass, c);

    pClass = new JLabel(MiniRPG.players.get(setupPlayerIndex).getclass());
    c.gridx = 2;
    c.gridy = 3;
    panel.add(pClass, c);

    lblRole = new JLabel("Role:");
    c.gridx = 1;
    c.gridy = 4;
    panel.add(lblRole, c);

    role = new JLabel(MiniRPG.players.get(setupPlayerIndex).getRole());
    c.gridx = 2;
    c.gridy = 4;
    panel.add(role, c);

    dash = new JLabel("--------------------STATS--------------------");
    c.gridwidth = 4;
    c.gridx = 1;
    c.gridy = 5;
    panel.add(dash, c);

    lblStr = new JLabel("Strengh:");
    c.gridwidth = 2;
    c.gridx = 1;
    c.gridy = 6;
    panel.add(lblStr, c);

    str = new JLabel(Integer.toString(
            minirpg.MiniRPG.players.get(setupPlayerIndex).getStr()));
    //c.insets = new Insets(5, 5, 5, 5);
    c.gridwidth = 1;
    c.gridx = 3;
    c.gridy = 6;
    panel.add(str, c);

    lblDex = new JLabel("Dexterity:");
    c.gridwidth = 2;
    c.gridx = 1;
    c.gridy = 7;
    panel.add(lblDex, c);

    dex = new JLabel(Integer.toString(
            minirpg.MiniRPG.players.get(setupPlayerIndex).getDex()));
    c.gridwidth = 1;
    c.gridx = 3;
    c.gridy = 7;
    panel.add(dex, c);

    lblEnd = new JLabel("Endurance:");
    c.gridwidth = 2;
    c.gridx = 1;
    c.gridy = 8;
    panel.add(lblEnd, c);

    end = new JLabel(Integer.toString(
            minirpg.MiniRPG.players.get(setupPlayerIndex).getEnd()));
    c.gridwidth = 1;
    c.gridx = 3;
    c.gridy = 8;
    panel.add(end, c);

    lblDex = new JLabel("Wisdom:");
    c.gridwidth = 2;
    c.gridx = 1;
    c.gridy = 9;
    panel.add(lblDex, c);

    wiz = new JLabel(Integer.toString(
            minirpg.MiniRPG.players.get(setupPlayerIndex).getWis()));
    c.gridwidth = 1;
    c.gridx = 3;
    c.gridy = 9;
    panel.add(wiz, c);

    lblHp = new JLabel("HP: ");
    c.gridx = 1;
    c.gridy = 10;
    panel.add(lblHp, c);


    health = new JLabel(Integer.toString(
            minirpg.MiniRPG.players.get(setupPlayerIndex).getHp()));
    c.gridx = 2;
    c.gridy = 10;
    panel.add(health, c);

    lblMoves = new JLabel("Moves Left: ");
    c.gridx = 1;
    c.gridy = 11;
    panel.add(lblMoves, c);

    movesLeft = new JLabel(Integer.toString(
            MiniRPG.players.get(setupPlayerIndex).getMoves()));
    c.gridx = 2;
    c.gridy = 11;
    panel.add(movesLeft, c);

    dash = new JLabel("--------------------SKILLS--------------------");
    c.gridwidth = 4;
    c.gridx = 1;
    c.gridy = 12;
    panel.add(dash, c);

    lblSkill1 = new JLabel("Skill 1:");
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy = 13;
    panel.add(lblSkill1, c);

    skill1 = new JButton(MiniRPG.players.get(setupPlayerIndex).getSkill1());
    c.gridx = 2;
    c.gridy = 13;
    panel.add(skill1, c);

    lblSkill2 = new JLabel("Skill 2:");
    c.gridx = 1;
    c.gridy = 14;
    panel.add(lblSkill2, c);

    skill2 = new JButton(MiniRPG.players.get(setupPlayerIndex).getSkill2());
    c.gridx = 2;
    c.gridy = 14;
    panel.add(skill2, c);
    skill2.setEnabled(false);

    lblSkill3 = new JLabel("Skill 3:");
    c.gridx = 1;
    c.gridy = 15;
    panel.add(lblSkill3, c);

    skill3 = new JButton(MiniRPG.players.get(setupPlayerIndex).getSkill3());
    c.gridx = 2;
    c.gridy = 15;
    panel.add(skill3, c);
    skill3.setEnabled(false);

    lblSkill4 = new JLabel("Skill 4:");
    c.gridx = 1;
    c.gridy = 16;
    panel.add(lblSkill4, c);

    skill4 = new JButton(MiniRPG.players.get(setupPlayerIndex).getSkill4());
    c.gridx = 2;
    c.gridy = 16;
    panel.add(skill4, c);
    skill4.setEnabled(false);        

    skill1.addActionListener(e);
    skill2.addActionListener(e);
    skill3.addActionListener(e);
    skill4.addActionListener(e);

    return panel;
}

How the Panel is added to the GUI

final JTabbedPane characterInfoPane = new JTabbedPane();
    while (setupPlayerIndex < 4) {
        JComponent panel = makeTextPanel("");
        characterInfoPane.addTab(minirpg.MiniRPG.players.get(setupPlayerIndex).getName(), null, panel,
                "");
        setupPlayerIndex++;
    }

how I am currently trying to change the relavent Label where x is the selected Player

movesLeft.setText(Integer.toString(MiniRPG.players.get(x).getMoves()));

please let me know if addition code is needed to Answer this Question of if it is possible to do what im looking for.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:15:32+00:00Added an answer on June 10, 2026 at 9:15 am

    Every time you create a new text pane, you are reassign the variable references. That is, movesLeft will ALWAYS refer to the last panel you created.

    Rather then creating the panels in the makeTextPane, I would create a custom panel that contained all the information that makeTextPane produces.

    I would then make setters & getters for all the relevent information you need to get and update.

    For example

    protected class TextPane extends JPanel {
    
        private JLabel name;
        private JLabel icon;
        private JLabel lblClass;
        private JLabel pClass;
        private JLabel lblRole;
        private JLabel role;
        private JLabel lblStr;
        private JLabel str;
        private JLabel lblDex;
        private JLabel dex;
        private JLabel lblEnd;
        private JLabel end;
        private JLabel wiz;
        private JLabel lblHp;
        private JLabel health;
        private JLabel lblMoves;
        private JLabel movesLeft;
        private JLabel lblSkill1;
        private JButton skill1;
        private final JLabel lblSkill2;
        private final JButton skill2;
        private final JLabel lblSkill3;
        private final JButton skill3;
        private final JLabel lblSkill4;
        private final JButton skill4;
    
        public TextPane() {
    
            //add(filler);
            setLayout(new GridBagLayout());
            GridBagConstraints c = new GridBagConstraints();
    
            JLabel dash;
    
            name = new JLabel(MiniRPG.MiniRPG.players.get(setupPlayerIndex).getName());
            c.insets = new Insets(5, 5, 5, 5);
            c.gridx = 0;
            c.gridy = 1;
            c.gridwidth = 2;
            add(name, c);
    
            icon = new JLabel(MiniRPG.players.get(setupPlayerIndex).getIcon());
            c.gridx = 1;
            c.gridy = 2;
            add(icon, c);
    
            lblClass = new JLabel("Class:");
            c.gridx = 1;
            c.gridy = 3;
            c.gridwidth = 1;
            add(lblClass, c);
    
            pClass = new JLabel(MiniRPG.players.get(setupPlayerIndex).getclass());
            c.gridx = 2;
            c.gridy = 3;
            add(pClass, c);
    
            lblRole = new JLabel("Role:");
            c.gridx = 1;
            c.gridy = 4;
            add(lblRole, c);
    
            role = new JLabel(MiniRPG.players.get(setupPlayerIndex).getRole());
            c.gridx = 2;
            c.gridy = 4;
            add(role, c);
    
            dash = new JLabel("--------------------STATS--------------------");
            c.gridwidth = 4;
            c.gridx = 1;
            c.gridy = 5;
            add(dash, c);
    
            lblStr = new JLabel("Strengh:");
            c.gridwidth = 2;
            c.gridx = 1;
            c.gridy = 6;
            add(lblStr, c);
    
            str = new JLabel(Integer.toString(
                    MiniRPG.MiniRPG.players.get(setupPlayerIndex).getStr()));
            //c.insets = new Insets(5, 5, 5, 5);
            c.gridwidth = 1;
            c.gridx = 3;
            c.gridy = 6;
            add(str, c);
    
            lblDex = new JLabel("Dexterity:");
            c.gridwidth = 2;
            c.gridx = 1;
            c.gridy = 7;
            add(lblDex, c);
    
            dex = new JLabel(Integer.toString(
                    MiniRPG.MiniRPG.players.get(setupPlayerIndex).getDex()));
            c.gridwidth = 1;
            c.gridx = 3;
            c.gridy = 7;
            add(dex, c);
    
            lblEnd = new JLabel("Endurance:");
            c.gridwidth = 2;
            c.gridx = 1;
            c.gridy = 8;
            add(lblEnd, c);
    
            end = new JLabel(Integer.toString(
                    MiniRPG.MiniRPG.players.get(setupPlayerIndex).getEnd()));
            c.gridwidth = 1;
            c.gridx = 3;
            c.gridy = 8;
            add(end, c);
    
            lblDex = new JLabel("Wisdom:");
            c.gridwidth = 2;
            c.gridx = 1;
            c.gridy = 9;
            add(lblDex, c);
    
            wiz = new JLabel(Integer.toString(
                    MiniRPG.MiniRPG.players.get(setupPlayerIndex).getWis()));
            c.gridwidth = 1;
            c.gridx = 3;
            c.gridy = 9;
            add(wiz, c);
    
            lblHp = new JLabel("HP: ");
            c.gridx = 1;
            c.gridy = 10;
            add(lblHp, c);
    
    
            health = new JLabel(Integer.toString(
                    MiniRPG.MiniRPG.players.get(setupPlayerIndex).getHp()));
            c.gridx = 2;
            c.gridy = 10;
            add(health, c);
    
            lblMoves = new JLabel("Moves Left: ");
            c.gridx = 1;
            c.gridy = 11;
            add(lblMoves, c);
    
            movesLeft = new JLabel(Integer.toString(
                    MiniRPG.players.get(setupPlayerIndex).getMoves()));
            c.gridx = 2;
            c.gridy = 11;
            add(movesLeft, c);
    
            dash = new JLabel("--------------------SKILLS--------------------");
            c.gridwidth = 4;
            c.gridx = 1;
            c.gridy = 12;
            add(dash, c);
    
            lblSkill1 = new JLabel("Skill 1:");
            c.gridwidth = 1;
            c.gridx = 1;
            c.gridy = 13;
            add(lblSkill1, c);
    
            skill1 = new JButton(MiniRPG.players.get(setupPlayerIndex).getSkill1());
            c.gridx = 2;
            c.gridy = 13;
            add(skill1, c);
    
            lblSkill2 = new JLabel("Skill 2:");
            c.gridx = 1;
            c.gridy = 14;
            add(lblSkill2, c);
    
            skill2 = new JButton(MiniRPG.players.get(setupPlayerIndex).getSkill2());
            c.gridx = 2;
            c.gridy = 14;
            add(skill2, c);
            skill2.setEnabled(false);
    
            lblSkill3 = new JLabel("Skill 3:");
            c.gridx = 1;
            c.gridy = 15;
            add(lblSkill3, c);
    
            skill3 = new JButton(MiniRPG.players.get(setupPlayerIndex).getSkill3());
            c.gridx = 2;
            c.gridy = 15;
            add(skill3, c);
            skill3.setEnabled(false);
    
            lblSkill4 = new JLabel("Skill 4:");
            c.gridx = 1;
            c.gridy = 16;
            add(lblSkill4, c);
    
            skill4 = new JButton(MiniRPG.players.get(setupPlayerIndex).getSkill4());
            c.gridx = 2;
            c.gridy = 16;
            add(skill4, c);
            skill4.setEnabled(false);
    
            skill1.addActionListener(e);
            skill2.addActionListener(e);
            skill3.addActionListener(e);
            skill4.addActionListener(e);
    
        }
    
        public void setMovesLeft(int value) {
            movesLeft.setText(Integer.toString(value));
        }
    
    }
    

    I would then keep a separate reference of each pane when I create it

    final JTabbedPane characterInfoPane = new JTabbedPane();
    
    TextPane[] textPanes = new TextPane[4];
    while (setupPlayerIndex < 4) {
        textPanes[setupPlayerIndex] = new TextPane();
        characterInfoPane.addTab(minirpg.MiniRPG.players.get(setupPlayerIndex).getName(), null, textPanes[setupPlayerIndex],
                "");
        setupPlayerIndex++;
    }
    

    This would then allow me to change a particular players moves simply by access setter of the TextPane

    textPanes[x].setMovesLeft(MiniRPG.players.get(x).getMoves());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four DIV elements on my page. Each has it's own array which
I have four divs each with the same ID but different class. <div id=inner
I have a Hgroup that contains of four panels. Sometimes it happens then when
i have four radio buttons , and i want to set a text for
I have four different lists. headers , descriptions , short_descriptions and misc . I
I have four UINavigationControllers assigned each to a tab in a UITabBarController. Each UINavigationController
I have an Xcode project. The project currently has four targets, and I am
I have an application that has multiple panels; I would like to have the
I have four tables each with its own form, all these table share same
I have four buttons which has click able property. Clicking on button will make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.