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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:18:24+00:00 2026-06-04T13:18:24+00:00

Okay, so in this program I’m making, users will be able to create shortcuts

  • 0

Okay, so in this program I’m making, users will be able to create shortcuts to their favorite apps on their computer. My program will be kind of like a hub, I guess, for apps. I have a small problem though, which involves two classes: AppButton and AppButtonContainer. They both implement MouseListener, but AppButton extends JComponent and AppButtonContainer extends JPanel. Basically, when an AppButton is clicked, it sets a draws the border in a different color to make it look selected. Otherwise, it sets the border to the background color. When you double click it, it opens up the application specified. I have a method in AppButton to remove the focus, and therefore setting the border to the background color. In AppButtonContainer, there is a bit of code so that when, the panel is clicked, it removes the focus from the AppButton.

That’s my problem, though. The AppButtonContainer doesn’t realize that it’s clicked. I’m thinking it has something to do with top level containers or something, but I’m not sure. Can anybody help?

EDIT: I found out that I didn’t put the addMouseListener(this) in the constructor of the AppButtonContainer. Thank you for everyone who helped me clear up this problem and give me tips along the way 🙂

AppButtonContianer:

public class AppButtonContainer extends JPanel implements MouseListener {
private static final long serialVersionUID = 6485231881729120957L;
public List<AppButton> appButtons;
private static final Color BACKGROUND_COLOR = new Color(18, 18, 18);

public AppButtonContainer(List<AppButton> buttons) {
    this.appButtons = buttons;
    setLayout(new GridLayout(5, 5, 20, 20));
    addButtonsToPane();
}

private void addButtonsToPane() {
    List<AppButton> buttons = this.appButtons;
    for (int i = 0; i < buttons.size(); i++) {
        this.add(buttons.get(i));
    }
}

private void removeAllButtonFocus() {
    for (int i = 0; i < this.appButtons.size(); i++) {
        this.appButtons.get(i).removeFocus();
    }
}

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(BACKGROUND_COLOR);
    repaint();
}

@Override
public void mouseClicked(MouseEvent e) {
    System.out.println("Pane Clicked");
    removeAllButtonFocus();
}

    ...Other MouseEvent methods
  • 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-04T13:18:26+00:00Added an answer on June 4, 2026 at 1:18 pm

    You can solve the problem at hand by putting addMouseListener(this) in the constructor for your AppButtonContainer class. Otherwise, it’ll never pick up mouse events.

    Generally, though, it’s not good to turn your classes into mouselisteners like that. Perhaps try making an inner class to listen for mouse events and pass them to the AppButtonContainer instead.

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

Sidebar

Related Questions

Okay so I made this program to help me out with my homework and
Okay, so here is the basic background. This program connects to outlook/exchange and parses
Okay, I have this program and I don't want more than one instance of
Okay, I tested this on an empty program, and just having a while(true){} running
Okay, I got this small program which tags (as in ID3v2.4 etc.) some music
Okay, so I have this Silverlight client program. I'm not allowed to use the
Okay this may be a simple question but I have yet to come with
Okay this is my 4th question today on Scheme, still pretty new to Scheme,
Okay this is werid, i keep getting the error, randomly. ValueError: matrix must be
Okay this is probably a really dumb question, however it's really starting to hurt.

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.