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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:22:13+00:00 2026-06-04T03:22:13+00:00

I have an extensive Gui with many components in it. There is a updateEnable()

  • 0

I have an extensive Gui with many components in it. There is a updateEnable() methods that updates the enable state of all the components based on some configuration.

I basically first set their enable state to true and then disable some of them (based on the configuration):

private void updateEnable() {
  enableAllRec(panel, true);
  // disable some components
}

private void enableAllRec(Container root, boolean b) {
  if (root == null) return;
  for (Component c : root.getComponents()) {
    c.setEnabled(b);
    if (c instanceof Container) enableAllRec((Container) c, b);
  }
}

The reason I do it like that is that some of the components are not stored as member variables and I don’t have access to them. They however can change their state because I initialized some of them like this (for example):

final JLabel exampleLabel = new JLabel("yoink");
final JCheckBox exampleCheckBox = new JCheckBox("boing");
exampleCheckBox.addItemListener(new ItemListener() {
  @Override
  public void itemStateChanged(ItemEvent e) {
    exampleLabel.setEnable(exampleCheckBox.isSelected());
  }
});

Now my problem is the following: When I call updateEnable(), some of the (stored) Components may flicker because they are enabled and then disabled again after some time. I would like to prevent that. My idea is to somehow prevent the GUI from refreshing until the very end of updateEnable() and then perform an updateUI(). But this is not very elegant AND I have no idea how to prevent the GUI from updating.

Am I missing a very elegant alternative solution for this problem?

Thanks a lot,
Stefan

  • 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-04T03:22:15+00:00Added an answer on June 4, 2026 at 3:22 am

    Ok, my approach seems to work. I just extended the enableAllRec(Container root, boolean b)to include some exclusions:

    private void enableAllRec(Container root, boolean defaultState, Set<Component> disableList, Set<Component> enableList) {
      if (root == null) return;
      for (Component c : root.getComponents()) {
        if (disableList != null && disableList.contains(c)) {
          c.setEnabled(false);
          disableList.remove(c);
        } else if (enableList != null && enableList.contains(c)) {
          c.setEnabled(true);
          enableList.remove(c);
        } else c.setEnabled(defaultState);
        if (c instanceof Container) enableAllRec((Container) c, defaultState, disableList, enableList);
      }
    }
    

    This way, I can determen all the components that I want to have enabled/disabled for sure, add them to their corresponding sets and thenn call the enableAllRec. Example:

    Set<Component> enableList = new HashSet<Component>();
    enableList.add(searchFreqButton);
    enableList.add(advMeasButton);
    enableAllRec(configPanel, false, null, enableList);
    

    Obviously, this is not ideal for large sets, but it is sufficient for my needs (arround 800 Components and the sets contain no more than arround 20-30 components). I suspect this method to easily handle larger sets as well.

    In the above example, it makes no sense to introduce a disableList (as all components will be disabled by default anyway). So depending on the default value, one can leave out the corresponding set. This should preferably be done in enableAllRec() of course.

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

Sidebar

Related Questions

I have a webforms page that makes quite extensive use of AJAX. There are
I have RCP, and 2 products, based on fetures. I have my.project.gui plugin, that
I have a page in one of my client's websites that generates an extensive
I have an old project that is mixed C and C++. It makes extensive
We have a command line application that could benefit from a GUI. We want
I have some Matlab code and a GUI for it and I want to
I have a stateless EJB-3.1 session bean containing an asynchronous method that does some
I'm technically savvy but don't have extensive experience with servers/daemons (I'm a Windows guy,
I have an extensive menu in which I would like to search for and
I have a simple unit test case (extensive question here ) on a configuration

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.