Setting focus onto an element

hi
i’m trying to set a focus to an element via my gamepad.

My current attempt is the following:

[java] if (containerPanel.getIsVisible()) {
selectedElement = (ButtonAdapter) iterator.previous();
/**
* TODO FIX that focus is set correct
*/
screen.setKeyboardElement(selectedElement);
screen.setTabFocusElement(selectedElement);
}[/java]
the returned element is the correct button,
but the element is not correctly highlighted( like moving a cursor over them) :/. Is there another way to focus elements correct?

@b00n said: hi i'm trying to set a focus to an element via my gamepad.

My current attempt is the following:

[java] if (containerPanel.getIsVisible()) {
selectedElement = (ButtonAdapter) iterator.previous();
/**
* TODO FIX that focus is set correct
*/
screen.setKeyboardElement(selectedElement);
screen.setTabFocusElement(selectedElement);
}[/java]
the returned element is the correct button,
but the element is not correctly highlighted( like moving a cursor over them) :/. Is there another way to focus elements correct?

Gimme a bit here. I need to go look up the proper way of setting tab focus. It’s a bit trickier than this, as it was initially supposed to be an internal only function. I think you have to notify the screen and the control of focus and lose focus if your setting it this way, as the screen is expecting some form of mouse/keyboard input to handle it properly.

1 Like

okay i have a dirty solution ^^…

here it is:

[java] private void selectPreviousElement() {
if (containerPanel.getIsVisible()) {
if (selectedElement != null) {
selectedElement.onLoseFocus(new MouseMotionEvent(0, 0, 0, 0, 0, 0));
}
selectedElement = (ButtonAdapter) iterator.previous();
selectedElement.onGetFocus(new MouseMotionEvent(0, 0, 0, 0, 0, 0));
}
}

    private void selectNextElement() {
        if (containerPanel.getIsVisible()) {
            if (selectedElement != null) {
                selectedElement.onLoseFocus(new MouseMotionEvent(0, 0, 0, 0, 0, 0));
            }
            selectedElement = (ButtonAdapter) iterator.next();
            selectedElement.onGetFocus(new MouseMotionEvent(0, 0, 0, 0, 0, 0));

// selectedElement.onMouseLeftPressed(new MouseButtonEvent(0, true, 0, 0));
}
}[/java]

@b00n said: okay i have a dirty solution ^^....

here it is:

[java] private void selectPreviousElement() {
if (containerPanel.getIsVisible()) {
if (selectedElement != null) {
selectedElement.onLoseFocus(new MouseMotionEvent(0, 0, 0, 0, 0, 0));
}
selectedElement = (ButtonAdapter) iterator.previous();
selectedElement.onGetFocus(new MouseMotionEvent(0, 0, 0, 0, 0, 0));
}
}

    private void selectNextElement() {
        if (containerPanel.getIsVisible()) {
            if (selectedElement != null) {
                selectedElement.onLoseFocus(new MouseMotionEvent(0, 0, 0, 0, 0, 0));
            }
            selectedElement = (ButtonAdapter) iterator.next();
            selectedElement.onGetFocus(new MouseMotionEvent(0, 0, 0, 0, 0, 0));

// selectedElement.onMouseLeftPressed(new MouseButtonEvent(0, true, 0, 0));
}
}[/java]

Have you just tried using a Form? This has tab focus all built into it. You could trigger the next previous event from your joystick or whatever.

@t0neg0d said: Have you just tried using a Form? This has tab focus all built into it. You could trigger the next previous event from your joystick or whatever.

checked it out.

it focuses the elements but ongetfocus() is’nt called. It means that a button for example does not play it’s hover effect.

1 Like
@t0neg0d said: Have you just tried using a Form? This has tab focus all built into it. You could trigger the next previous event from your joystick or whatever.

So after a nap, i respottet your code about forms and i’m rewriting my stuff to use the forms. I recognized that LoginBox has an additional form-member instead of using the form of element.

edit:
i dit a little test:
[java]Field field = LoginBox.class.getDeclaredField(“form”);
field.setAccessible(true);
Form form = (Form) field.get(loginWindow);[/java]

and it works correct with my gamepad.

Can you tell me what the future of element.form is? Will it be removed or is the form of loginbox removed?

edit2:

is there a possibility to add a getSelectedElement() method to the Form class?