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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:50:42+00:00 2026-05-19T23:50:42+00:00

I am getting truble to repaint the JPanel in Gui builder can any body

  • 0

I am getting truble to repaint the JPanel in Gui builder can any body help me please.
here is main class that generate random Numbers in its Constructor

public class Main {
public static int q;
public Main(){

     Random randomGenerator = new Random();
            for (int idx = 1; idx <= 10; ++idx) {
                q = randomGenerator.nextInt(100);
            }
}

here is button click event in class A that include JPanel as custom code

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    new Main();
    Jpl jpl=new Jpl();   

}

Here is a class that add as custome component to class A

public class Jpl extends JPanel {

public Jpl() {
    printMe(Main.q);
}


public int printMe(int q) {
        removeAll();
    for (int i = 0; i <q; i++) {
        System.out.println("rinting lable");
        String htmlLabel = "<html><font color=\"#A01070\">" + i + " New Lable </font></html>";
        JLabel lbl = new JLabel(htmlLabel);
        setLayout(new GridLayout(0, 1));
        add(lbl, Jpl.RIGHT_ALIGNMENT);
        lbl.setForeground(Color.BLUE);
        Border border = BorderFactory.createLineBorder(Color.lightGray);
        lbl.setBorder(border);
        lbl.add(new JSeparator(SwingConstants.HORIZONTAL));

        lbl.addMouseListener(new MouseAdapter() {

            @Override
            public void mousePressed(MouseEvent e) {
                JLabel label = (JLabel) e.getSource();
                JOptionPane.showMessageDialog(null, "You Slected");
                System.out.println(label.getText() + "NO AKKA is Selected");
            }
        });
    }

    revalidate();
    repaint();
    return 1;

}
  • 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-19T23:50:43+00:00Added an answer on May 19, 2026 at 11:50 pm

    One problem: In your ActionListener code, you create a new JPanel (or Jpl) object:

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        Jpl jpl=new Jpl();
        int a= jpl.printMe(4);
    }
    

    but there is absolutely no way that this is the Jpl object that is displayed in your GUI. Yes it is an object of the same class, but it is a completely new different and distinct object from the one being displayed, and so calling a method on it will have no effect on the displayed Jpl object. The solution is to call your methods only on the displayed object. I cannot tell you how to get a reference to that object since we are not privy to the rest of your code where you display it.

    The other problem is that you haven’t asked a question in this post, so I have no idea if my suggestion will help your primary problem (but I do know that it will solve a problem). So I suggest that you ask a proper question so we can better understand the issues and that you’ll likely need to post more code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

having trouble getting my directx going I get the following error 1>Linking... 1>main.obj :
Having trouble getting my JQuery POST to be accepted by the WCF Service. Here's
Having trouble getting this to work. What's strange is that I have 10 bookmarks
I'm having some truble redirecting my users to the previous page. Here is an
Having trouble getting the id of divs on my page that begin with refresh.
I'm having trouble getting a filter to work on a BindingSource that is the
Im having trouble getting this to work, here´s a quick overview of the idea.
I have trouble getting Application Data in Lua. I can't even find how to
I just upgradated my django to 1.4. I am getting trouble with haystack app.
Getting started with jquery and having trouble getting hello world type example going for

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.