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 8513301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:31:38+00:00 2026-06-11T04:31:38+00:00

I am trying to create dynamic JButton and JLabel based on the number of

  • 0

I am trying to create dynamic JButton and JLabel based on the number of URLs defined in the properties file.

What I have tried so far is:

AppResources.properties file

urls=http://google.com,http://stackoverflow.com,http://gmail.com
urlLabels=Internet Users,MPLS Users,Physical Access (Not Advised)

In my Java program I am reading the properties file and based on the comma separator splitting the string and now i need to generate the buttons and labels accordingly. Like the first URL Label --> first URL as Button and so on.

The way I have done this so far is:

String url = properties.getProperty("urls");
        String urlLabel = properties.getProperty("urlLabels");
        String[] jButton = url.split(",");
        String[] jLabel = urlLabel.split(",");


        for (int i = 0; i < jLabel.length; i++) {
        JLabel labels = new JLabel(jLabel[i]);
        panel.add(labels);
        for (int j = 0; j < jButton.length; j++) {
            JButton button = new JButton(jButton[j]);
            panel.add(button);
        }
        }

But it prints the button three times for a label. How to fix this? Also how to write the action listeners for these buttons?

  • 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-11T04:31:39+00:00Added an answer on June 11, 2026 at 4:31 am

    If you want to implement action listeners for your buttons, you can simply create and add a new ActionListener while creating the button.

    Example :

    for (int i = 0; i < jLabel.length; i++) {
        final String str = jLabel[i];
        JLabel labels = new JLabel(str);
        panel.add(labels);
        JButton button = new JButton(jButton[i]);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(panel, str);
            }
        });
        panel.add(button);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a dynamic row filter based on a variable. I have
I'm trying to create a dynamic point system based off of how much money
I'm trying to create a dynamic regex to select URL's based on a segment
So here is the problem: I am trying to create dynamic buttons that have
I am trying to create a dynamic menu by reading an XML file using
I'm trying to create a dynamic report in Excel. I have lots of sales
I am trying to create a dynamic CSS file using the Django templating engine
I am trying to create a dynamic website, I have a database with some
I am trying to create a dynamic table that is being built based on
I'm trying to create a linq query based on some dynamic/optional arguments passed into

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.