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

  • Home
  • SEARCH
  • 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 6896273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:00:54+00:00 2026-05-27T07:00:54+00:00

FIXED I’m sorry for the bad title, but I spend 5 minuits on it

  • 0

FIXED

I’m sorry for the bad title, but I spend 5 minuits on it and can’t phrase it better sorry.

I need to have it so that if you press JButton all, it takes the image in all2 and also puts that into JLabel label (made with a list)

I put the JLabel all2 above map() because if I didn’t, “ImageIcon setAll can’t be resolve”. I didn’t put JLabel label above map() because it messes up with the creation of the 100 JLables made with the list listofLabels. All that it would show was one sigle Label.enter image description here
enter image description here

public class mapMaker {

ArrayList<JLabel> listofLabels = new ArrayList<JLabel>(100);
ImageIcon forest = new ImageIcon("resources/terrains/forest.jpg");
ImageIcon wood = new ImageIcon("resources/terrains/wood.jpg");

JFrame frame = new JFrame("D&D");
JLabel all2=new JLabel( wood);



public map() {
    int a=0,b=50;
    JFrame.setDefaultLookAndFeelDecorated(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(100,0,1000,700);
    frame.getContentPane().setLayout(null);
    frame.setVisible(true);


    JButton all=new JButton("Set All To");
    frame.getContentPane().add(all);
    all.setBounds(600,450,150,50);
    all.setFont(new Font("Courior", Font.BOLD, 25));
    all.addActionListener(boardListener);

    frame.getContentPane().add(all2);
    all2.setBounds(800,450,50,50);
     all.addActionListener(boardListener);


for ( i = 0; i < 100; i++) {
    JLabel label =new JLabel(forest);    
    label.setIcon(forest);
        listofLabels.add(label);
        a=a+50;
        if(a>549) {
            b=b+50;
            a=50;
        }
        frame.getContentPane().add(label);
        label.setBounds(a, b, 50,50);
        label.setTransferHandler(new TransferHandler("icon"));


            }
}


ActionListener boardListener = new ActionListener (){
    public void actionPerformed(ActionEvent e){
ImageIcon setAll=(ImageIcon) all2.getIcon();

![enter image description here][2]label.setIcon(setAll);



    }
    };;

public static void main(String[]args) {
    new map();
}

}

  • 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-05-27T07:00:55+00:00Added an answer on May 27, 2026 at 7:00 am

    Why not simply iterate through the array (or ArrayList) of JLabels setting all of the JLabel’s Icons to the one selected?

    For example:

    ActionListener boardListener = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
         if (e.getActionCommand().equals("Set All To")) {
            ImageIcon setAll = (ImageIcon) all2.getIcon();
            for (JLabel label : listofLabels) {
               label.setIcon(setAll);
            }
         }
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FIXED! I have 2 php pages that both define the variable title as something
Possible Duplicate: CSS: fixed position on x-axis but not y? I have a HTML
I have a fixed-length data file need to persistence into database. I use a
I have a fixed width DIV containing a table with many columns, and need
I've got a fixed div on the left of a page that can scroll
I have a fixed container and inside of that is an additional container which
I have a fixed-position image that I would like to fade out when scrolling
Fixed: See notes at bottom I am implementing a generic class that supports two
I have a fixed strip I'm drawing, 50 pixels in height and as wide
How can a fixed character limit be imposed on a text field in Cocos2d?

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.