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

  • Home
  • SEARCH
  • 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 963209
In Process

The Archive Base Latest Questions

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

In order to represent a List of Objects with different colors in a GWT-Widget,

  • 0

In order to represent a List of Objects with different colors in a GWT-Widget, we need to get dynamically a List of colors with as much different colors as objects. Since the size of the List can vary, we need to be able to compute such a List of colors.

  • 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-16T01:38:20+00:00Added an answer on May 16, 2026 at 1:38 am

    Another version of my solution with ranges:

    List<int> getUniqueColors(int amount) {
        final int lowerLimit = 0x10;
        final int upperLimit = 0xE0;    
        final int colorStep = (upperLimit-lowerLimit)/Math.pow(amount,1f/3);
    
        final List<int> colors = new ArrayList<int>(amount);
    
        for (int R = lowerLimit;R < upperLimit; R+=colorStep)
            for (int G = lowerLimit;G < upperLimit; G+=colorStep)
                for (int B = lowerLimit;B < upperLimit; B+=colorStep) {
                    if (colors.size() >= amount) { //The calculated step is not very precise, so this safeguard is appropriate
                        return colors;
                    } else {
                        int color = (R<<16)+(G<<8)+(B);
                        colors.add(color);
                    }               
                }
        return colors;
    }
    

    This one is more advance as it generates the colors that differ from each other as much as possible (something like @aiiobe did).

    Generally we split the range to 3 subranges of red green and blue, calculate how many steps do we need to iterate each of them (by applying a pow(range,1f/3)) and iterate them.

    Given the number 3 for example, it will generate 0x0000B1, 0x00B100, 0x00B1B1. For number 10 it will be: 0x000076, 0x0000EC, 0x007600, 0x007676, 0x0076EC, 0x00EC00, 0x00EC76, 0x00ECEC, 0x760000, 0x760076

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

Sidebar

Related Questions

In Scala I have a list of objects that represent points and contain x
I am trying to understand how prolog represent first order logic. how can I
I'm just curious if there's a reason why in order to represent -1 in
order by in query is taking to much time in MySQL. SHOW PROFILES shows
I would like to sort a list of strings which represent paths. The sort
I want to represent the list hi, hello, goodbye, good day, howdy (with that
I have multiple text files that represent logging entries which I need to parse
I have a list of items that have a partial order relation , i.
I use a GLMmodel object in order to represent a Google Sketch Up model
What would be an elegant way to represent an arbitrary total order between elements

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.