-1

I'm trying to use a TextButton with a ColorMenu as a color chooser.

TextButton button = new TextButton("SelectColor");
ColorMenu cm = new ColorMenu();
button.setMenu(cm);
add(new FieldLabel(button, "Color"));`

When I click on the button, the colormenu is correctly displayed. However, if I select a color, the menu doesn't close.

How can I achieve that?

MrTux
  • 32,350
  • 30
  • 109
  • 146

1 Answers1

1

The ColorMenu or better the ColorPalette has its own handlers which one has to use:

TextButton button = new TextButton("SelectColor");
final ColorMenu cm = new ColorMenu();
cm.getPalette().addValueChangeHandler(new ValueChangeHandler<String>() {
    @Override
    public void onValueChange(ValueChangeEvent<String> event) {
        cm.hide();
        // do other stuff, selected color is provided in event.getValue()
    }
});
button.setMenu(cm);
add(new FieldLabel(button, "Color"));
MrTux
  • 32,350
  • 30
  • 109
  • 146