PDA

View Full Version : Problem creating a colorMenu with custom colors



Matt202
1 Oct 2009, 11:52 PM
Hello! I am trying to make a color menu that only displays certain colors. My reading of the api tells me this is how to do it:
Using Ext 2.2

colorPalette=new Ext.ColorPalette();
colorPalette.colors=['CC99FF','33CCCC','FFFFFF','000000'];
colorMenu=new Ext.menu.ColorMenu();
colorMenu.palette=colorPalette;
colorMenu.showAt([50,50]);

This still shows the default color choices. After some experimenting I was able to find a way to only display the colors I want, but the selection box is full size, and this seems like a hack and to the right way to do it

colorMenu.items.items[0].palette=colorPalette;
colorMenu.items.items[0].component.colors=colorPalette.colors;

Anyone have any ideas?

Condor
2 Oct 2009, 1:11 AM
Why not use:

var colorMenu = new Ext.menu.ColorMenu({
colors: ['CC99FF', '33CCCC', 'FFFFFF', '000000']
});
colorMenu.showAt([50, 50]);

Matt202
2 Oct 2009, 2:28 AM
Thanks for the reply! That is a lot shorter way of writing the second method i tried, but it has the same result, the box containing the color options is still fullsized. Do I have to manually resize it to fit the number of available colors?

Condor
2 Oct 2009, 2:41 AM
Yes, unfortunately ColorPalette doesn't autosize based on the number of colors.

You'll need to use:

var colorMenu = new Ext.menu.ColorMenu({
colors: ['CC99FF', '33CCCC', 'FFFFFF', '000000'],
width: 80,
height: 26
});
colorMenu.showAt([50, 50]);

Condor
2 Oct 2009, 3:16 AM
Or you could use this (http://www.extjs.com/forum/showthread.php?t=81934).