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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:45:27+00:00 2026-06-02T20:45:27+00:00

I am implementing the enum class which I will use to retrieve some background

  • 0

I am implementing the enum class which I will use to retrieve some background in application,
a current implementation of this class is here:

public enum Painters{

    /**
     * Available painters.
     */
    Background(getBackgroundPainter()),
    InactiveBackground(getInactiveBackgroundPainter()),
    DesktopBackground(getBackgroundPainter());

    /**
     * The background painter.
     */
    private Painter<Component> _painter;

    /**
     * Constructor will initialize the object.
     */
    Painters(Painter<Component> painter){
        _painter = painter;
    }

    /**
     * Will return a current painter.
     * @return instance of Painter<Component>
     */
    public Painter<Component> painter(){
        return _painter;
    }

    private static Painter<Component> getBackgroundPainter(){
        MattePainter mp = new MattePainter(Colors.White.alpha(1f));
        PinstripePainter pp = new PinstripePainter(Colors.Gray.alpha(0.2f),45d);
       return (new CompoundPainter<Component>(mp, pp)); 
    }

    private static Painter<Component> getInactiveBackgroundPainter(){
        MattePainter mp = new MattePainter(Colors.White.alpha(1f));
        GlossPainter gp = new GlossPainter(Colors.Gray.alpha(0.1f), GlossPainter.GlossPosition.BOTTOM);
        PinstripePainter pp = new PinstripePainter(Colors.Gray.alpha(0.2f), 45d);
        return (new CompoundPainter<Component>(mp, pp, gp));    
    }
}

My problem is that I need to call the painter() method each time I trying to get a painter but I prefer just to write the type of the painter instead. I thought that if I can to extend the Painter by my enum then probably I will get the right functionality, but it looks that it is not possible in java.

public enum Painters extends Painter<Component>

Do you know any solution for this problem???

Currently I am using it in this way:

Painters.Background.painter();

but I need:

Painters.Background;
  • 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-02T20:45:31+00:00Added an answer on June 2, 2026 at 8:45 pm

    You could always define your painter as an interface and have your enum implement it. You won’t be able to use generic wildcards, but as long as thats not a constraint you will be able to reference the painter in code the way you are wanting too:

    interface Painter<T> {
        // ...
    }
    
    public enum Painters implements Painter<Component> {
        Background(getBackgroundPainter()),
        InactiveBackground(getInactiveBackgroundPainter()),
        DesktopBackground(getBackgroundPainter());
    
        private Painter<Component> _painter;
    
        // ...
    }
    
    Painter somePainter = Painters.Background;
    

    Your enum would effectively be proxying over actual painter implementations.

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

Sidebar

Related Questions

I'm using an enum singleton, but implementing logging is troublesome. This: public enum Foo
Implementing Equals() for reference types is harder than it seems. My current canonical implementation
My Grails application has a large number of enums that look like this: public
I want to take an object, let's say this object: public class BenchmarkList {
I started with this code snippet, which, by my understanding, is essentially a class-factory
I often find myself implementing a class maintaining some kind of own status property
I am trying to do reverse lookup on few enum classes implementing same Field
Consider the simple example below of implementing a method in an Enum. One problem
Implementing the ScriptControlClass was extremely easy, unfortunately the side effects with the language implementation
implementing publishActivity in PHP using the REST API using this code: $activity = array(

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.