Listbox Keyboard/Controller Navigation Issue

       var mainRow = 0;
        var title = utils.addTitle(mainWindow, "", mainRow++, 0);
        title.setBackground(backgroundImage);
        var credits = new Container();
        var listBox = mainWindow.addChild(new ListBox<String>(), mainRow++, 0);
        listBox.setVisibleItems(15);

        var nextItem = 0;
        for( int i = 0; i < 30; i++ ) {
            listBox.getModel().add("Dummy list entry " + nextItem);
            nextItem++;
        }
        utils.addLabel(mainWindow, "", mainRow++, 0);
        utils.addButton(mainWindow, "Back", this, "back", mainRow, 0);
        utils.centerMainPanel(mainWindow);

This makes me a list of 15 visible entries, including a slider (which I don’t really need, but that is ok for now). I have only keyboard or game controller to navigate.

My issue is that with the up/down arrows I can select the up scroll and down scroll arrow, but to go down to the “Back” button, I have to hit 15 times (the list items it looks like) until I’m on the active Back button.

What I want in the end is a slow autoscroll as soon I have the credits screen open and an active “Back” button. Or a the very least only the scroll part and the button should be navigated but not the list entries.

The focus traversal for any panel can be overridden. You just need to add a control that implements FocusTraversal. (Lemur/src/main/java/com/simsilica/lemur/focus/FocusTraversal.java at master · jMonkeyEngine-Contributions/Lemur · GitHub)

…unfortunately, I think this was not entirely wired up because reading the code I think that the GuiControl will be caught first if you try to add your own FocusTraversal implementation.

But it’s somewhere in and around that capability.

I do wonder if a list box is really what you want here since you don’t want to be able to navigate the children and you don’t want the scroll bar. Why use a list box at all?

1 Like

True, I figured a solution and did my own ScrollContainer with a method scroll which does scroll one line up when calling scroll() :slight_smile: It does it endlessly (starts over if the end is met).

It is a line by line scrolling, but a smooth scrolling would be cooler, have to think of a solution. Not a pressing issue tho, but wouldn’t mind some ideas :smiley:

Is this full screen or just in a smaller window or something?

It is a smaller window, above the window is a graphic placed and below is an active “Back” button to leave that Credits screen.

To have smooth scrolling where the clipping was also smooth… the easiest is probably to stick it in a viewport.

And if it’s in a viewport then it could be even less fancy… just one big giant panel if Labels that you slowly scroll through the viewport.

1 Like

Sounds like a good solution. Have to get my head around jme view ports first I guess, never did anything consciously with them. Even an endless scroll is easily done that way just reset it after last line is out.

The lemur demos have an example of using viewports, if it helps.

1 Like

Ah, that helps indeed! Thank you! I can even use this for my character selection screen. Cool.