0

I have a

ComboBox cmb = new ComboBox();

I would like to display a list of colors, if possible ordered from brighter to darkest, but I haven't find any working example

How to render a combobox in order to display a list of color?

Any help really appreciated

Thanks

Edit: question closed, solved by myself, thanks all.

Alberto acepsut
  • 1,972
  • 10
  • 41
  • 87
  • Alberto, you are a developer working with JavaFX for quite a long time. Please provide your coding effort, investigation on the net, other stuff. See these links for reference: [example of color patterns for listview (the same semantics are also valid for combobox)](http://docs.oracle.com/javafx/2/ui_controls/list-view.htm#CEGIIDDC) and [Combo-box key value pair in JavaFX 2](http://stackoverflow.com/q/10699655). Try to combine these two tutorials. If you stuck somewhere then update your question accordingly. Good luck! – Uluk Biy Jun 25 '13 at 12:51

1 Answers1

0

To calculate brightness (for sorting) use the luminosity coefficients:

var color = Color.FromArgb(240,230,210); // use whatever color you're wanting to rank
var luminosity = 0.299*color.R + 0.587*color.G+ 0.114*color.B;

As for rendering it into a combobox, I know it can't be done with the standard Window Forms Combobox. But, it wouldn't be too hard to make your own ComboBox control. I would guess you could do it pretty readily in WPF. As for the approach to take - you'll need to generate a graphics object and draw rectangles of the color onto the control - or draw to an in-memory bitmap and set a picturebox's image property to that image. Good luck!

RutledgePaulV
  • 2,568
  • 3
  • 24
  • 47