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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:20:52+00:00 2026-05-23T01:20:52+00:00

I have a custom button class called ImageButton that extends JButton. In it i

  • 0

I have a custom button class called ImageButton that extends JButton. In it i have a setEnabled method that I want to be called rather than the JButton’s setEnabled method.

My code is below. In my other class I create a new instance of ImageButton, but when I try to use the setEnabled method, it goes straight to the JButton’s setEnabled method. Even before I run the code, my IDE is telling me that the ImageButton’s setEnabled method is never used. If I change the method to “SetOn” it works fine. So why is it that I can’t use the same name as that of the super class? I thought it’s supposed to hide the superclass method if it’s the same name?

public class ImageButton extends JButton{

    public ImageButton(ImageIcon icon){
        setSize(icon.getImage().getWidth(null),icon.getImage().getHeight(null));
        setIcon(icon);
        setMargin(new Insets(0,0,0,0));
        setIconTextGap(0);
        setBorderPainted(true);
        setBackground(Color.black);
        setText(null);
    }

    public void setEnabled(Boolean b){
        if (b){
            setBackground(Color.black);
        } else {
            setBackground(Color.gray);
        }
        super.setEnabled(b);
    }
}
  • 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-23T01:20:52+00:00Added an answer on May 23, 2026 at 1:20 am

    You need to change

    public void setEnabled(Boolean b){
    

    to

    public void setEnabled(boolean b){
                           ^
    

    (By using Boolean instead of boolean you’re overloading the method instead of overriding it.)


    I encourage you to always annotate methods intended to override another method with @Override. If you had done it in this case, the compiler would have complained and said something like

    The method setEnabled(Boolean) of type ImageButton must override or implement a supertype method.

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

Sidebar

Related Questions

I have a custom control derived from Button: class MyControl : Button{} And suppose,
I have a Button and the button content is binded to a custom class
I have a sheet with a custom button on it from where I control
I'm trying to create a custom control - a button - which will have
I want to double buffer a custom control which contains buttons. I have tried
I have a few models that need to have custom find conditions placed on
I have created a class, that makes it easy to enter in the amount
Well i have a custom control called Dialog to slim it down to the
I have a custom EntityHome class. I wire the dependent entity in the wire
I have created a custom subclass of UIView for an interface element that I

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.