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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:51:51+00:00 2026-05-16T09:51:51+00:00

I’d like to load a series of Swing Actions into a container at runtime

  • 0

I’d like to load a series of Swing Actions into a container at runtime and access them by a constant name as is possible with an Enum. The purpose of this would be to both restrict the Actions possible and also improve readability.

Initially, I was considering a sort of dynamic enum (see http://blog.xebia.com/2009/04/02/dynamic-enums-in-java/) but as Java Drinker points out below this is unnecessary since the actions remain unchanged.

Ideally, what I’d like to do is a sort of wrapper that contains AbstractAction instances which could be enabled/disabled and be able to refer to each action through a symbolic name.

Edit: Question has been reformulated.

  • 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-16T09:51:51+00:00Added an answer on May 16, 2026 at 9:51 am

    You can do something like this:

    public enum Actions {
        COPY( new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                //do something
            }
        }),
        PASTE( new PasteAction() );
    
        public final AbstractAction action;
        private Actions(AbstractAction action) {
            this.action = action;
        }
    
    }
    
    //...
    Actions.COPY.action...;
    

    And then as others have said, use the enum in conjunction with an EnumSet or EnumMap. Personally, I don’t see a huge value in it over just having a few named fields without an enum.

    I think what you really want is some kind of Action registry like this:

    public class ActionsManager {
        private final Map<String, Action> actions;
        private final Map<User, Set<String>> enabledActions;
        public Action get(String id);
        public void register(String id, Action action);
        public void deregister(String id);
        public boolean isEnabled(User user, Action action);
    }
    

    Implementation left as an exercise.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I would like to count the length of a string with PHP. The string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.