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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:21:08+00:00 2026-06-05T05:21:08+00:00

I am developing a large scale (at least for me) gui with a lot

  • 0

I am developing a large scale (at least for me) gui with a lot of components. There is some quite complex mechanics behind the enabling rules (meaning what component has to be enabled/disabled depending on the status of other components). Every time I do an update of the whole user interface (which is not that often but sometimes neccessary, for instance after loading up a settings file), I have to go through the rule sets to set every component. What I basically do is the following:

meaningfulName1.setEnabled(conditionForMeaningfulName1());
meaningfulName2.setEnabled(conditionForMeaningfulName2());
meaningfulName3.setEnabled(conditionForMeaningfulName3());
// etc

I ask myself if it makes sense to instead do the following.

boolean temp = conditionForMeaningfulName1();
if (meaningfulName1.isEnabled != temp) meaningfulName1.setEnabled(temp);
temp = conditionForMeaningfulName2();
if (meaningfulName2.isEnabled != temp) meaningfulName2.setEnabled(temp);
temp = conditionForMeaningfulName3();
if (meaningfulName3.isEnabled != temp) meaningfulName3.setEnabled(temp);
// etc

The idea behind that would be that it saves some performance to not set the flag if the state is already the desired one and therefore save some graphical updating (as well as a function call).

Do you think this makes sense on a large scale or doesn’t it save any time at all and just makes the code less readable?

  • 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-05T05:21:11+00:00Added an answer on June 5, 2026 at 5:21 am

    Following the comment of Andrew Thompson I created a small test. I did not use profiling or so, just very simple System.currentTimeMillis(). Obviously the first few runs have to be neglected, but after that it seems like there is no difference to the two methods.

    import java.awt.GridLayout;
    import java.util.Random;
    import java.util.Vector;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    public class Main {
        public static Vector<int[]> v;
        public static JButton[][] buttons;
        public static int n1 = 100, n2 = 100, N = 50000;
    
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.setLayout(new GridLayout(n1, n2));
    
            buttons = new JButton[n1][n2];
            for (int i = 0; i < n1; i++) {
                for (int j = 0; j < n2; j++) {
                    buttons[i][j] = new JButton(String.format("%d,%d", i, j));
                    f.add(buttons[i][j]);
                }
            }
            f.setSize(1024, 768);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    
            v = new Vector<int[]>();
            Random r = new Random();
            for (int i = 0; i < N; i++)
                v.add(new int[] {r.nextInt(n1), r.nextInt(n2), r.nextInt(2)});
    
            for (int i = 0; i < 10; i++) {
                test1();
                test2();
            }
        }
    
        public static void test1() {
            reset();
            new Thread(new Runnable() {
                @Override
                public void run() {
                    long start = System.currentTimeMillis();
                    for (int[] test : v) {
                        buttons[test[0]][test[1]].setEnabled(test[2] == 1);
                    }
                    System.out.println(String.format("Test1   -> took %dms", System.currentTimeMillis() - start));
                }
            }).start();
        }
    
        public static void test2() {
            reset();
            new Thread(new Runnable() {
                @Override
                public void run() {
                    long start = System.currentTimeMillis();
                    for (int[] test : v) {
                        if (buttons[test[0]][test[1]].isEnabled() != (test[2] == 1)) buttons[test[0]][test[1]].setEnabled(test[2] == 1);
                    }
                    System.out.println(String.format("Test2   -> took %dms", System.currentTimeMillis() - start));
                }
            }).start();
        }
    
        public static void reset() {
            for (int i = 0; i < n1; i++) {
                for (int j = 0; j < n2; j++) {
                    buttons[i][j].setEnabled(true);
                }
            }
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {}
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're developing a pretty large application with MVC 2 RC2 and we've received some
I'm developing a large scale application for iOS 5 using ARC in xcode. The
I'm about to start developing a large-scale system and I'm struggling with which direction
I am developing a large program which uses a lot of memory. The program
I'm developing a large scale website and when I was checking linq queries with
A little background I'm developing a large-scale JS app with ExtJS3. At runtime, the
I am developing a large scale application in C++. The application also maintains a
We are developing an open source and free large scale database driven web application.
I am currently in the process of developing a fairly large and complex user
We are developing large ASP.NET applications with lot of dynmically created pages containing ASCX

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.