shortcut listeners for accordion in vaadin

Hello,
i’m new to vaadin, i want to add shortcut keys for accordion items.


i want to have a keyboard shortcut key for the accordion items to select
for example:
if i press “ALT+1” first item of the accordion should be selected…
.
.
if there is any solution please let me know…

You can use generic shortcut actions: https://vaadin.com/book/-/page/advanced.shortcuts.html

private Action shortcutFirstTab = new ShortcutAction("Alt+0",
        ShortcutAction.KeyCode.NUM0,
        new int[] { ShortcutAction.ModifierKey.ALT });

private Accordion accordion;

protected void init(VaadinRequest request) {
    Panel panel = new Panel();
    setContent(panel);

    accordion = new Accordion();
    accordion.addTab(new Label("Label 0"), "Tab 0");
    accordion.addTab(new Label("Label 1"), "Tab 1");

    panel.setContent(accordion);
    panel.addActionHandler(this);
}

public Action[] getActions(Object target, Object sender) {
    return new Action[] { shortcutFirstTab };
}

public void handleAction(Action action, Object sender, Object target) {
    if (action == shortcutFirstTab) {
        accordion.setSelectedTab(0);
    }
}

Thank you so much sir… That really helped me…

can we highlight single letter from each button having shortcut key, when we hold a modifier key?