Reputation: 1
I am printing multiple labels and on click I am changing the clicked label color. I want to reset the clicked label color when I click on another label.
final Label functionLabel = new Label(FDTO.getFunctionName());
functionLabel.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
functionLabel.getElement().getStyle().setColor("red");
// checkChild(FDTO.getFunctionCode(), functions, qaDTO, val);
}
});
childPanel.add(functionLabel);
Upvotes: 0
Views: 72
Reputation: 7273
Unlike RadioButton
s which can be grouped together, Label
s are stand-alone elements, and there's no out-of-the-box way of doing what you want.
The most straightforward way to do so would be to manually change the color of every other label from within this label's onClick
method, either one by one or iterating through some list/array where you keep them all.
Something along the lines of:
List<Label> myLabels = Arrays.asList(functionLabel, errorLabel, someOtherLabel);
//...
functionLabel.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
for (Label l : myLabels) {
l.getElement().getStyle().setColor("black");
}
functionLabel.getElement().getStyle().setColor("red");
// checkChild(FDTO.getFunctionCode(), functions, qaDTO, val);
}
});
Upvotes: 1