1
votes

I want to get my generic Picker component to load Preferences on creation and save them on change.

I can easily do the same with a TextField or a CheckBox with the following idiom

    checkBox.setSelected(Preferences.get(key, false));
    checkBox.addFocusListener(new FocusListener()
    {
        @Override
        public void focusGained(final Component cmp)
        {

        }

        @Override
        public void focusLost(final Component cmp)
        {
            Preferences.set(key, checkBox.isSelected());
        }
    });

But, for Picker and PickerComponent the idiom is not working since the focus listener is not effective.

How can this be achieved :(

Thank you!

1

1 Answers

0
votes

Picker is a button and should work fine with focus event but it might broadcast the event after the click was finished. Generally, focus events are designed for key navigation so I wouldn't do it in that way for a touch device. They are too verbose and can result in sub par behavior.

I would suggest flipping the switch in the checkbox action listener instead of refreshing it via focus.