ScrollArea remove Elements/Hook ESC Key

Hey Guys,

I am having two different problems so far:
a) Since I have a FPS I overrode(?) the Window-Class to handle inputManager.setShowCursor()
My Problem is, that only works when clicking on the “close-button” which class hideWindow().

I’d want to also hook the ESC-KeyPress but unfortunately I couldn’t find some “onKeyboardPress” in neither Element or Window class. I’ve found some KeyboardListener Interface but no way to attach it to a Window class. How can I do that?


b) I am having a ScrollArea and despite my anticipation, I need to manually calculate the position (so if I add another item, I need to enhigher it’s coordinates). This leads to problems when I remove an Item. I would have to get all items under me and move them up.

The only question is, is there any align/rearrange method which does that for me?
And if not, is there an easy way to find out which child is below or do I need to iterate over all childs and compare their position?

Edit: How Can I iterate over the children at all? Using scrollArea.scrollableArea.children and then cast all the Spatials to Elements?

Edit2: I coded something for case b) though it doesn’t seem to work correctly, it sometimes leaves a blank space.

for (Element e : scrollableArea.getElements()) /* we need the reverse order for it to work */
            if (e.getY() < after.getY()) /* We are after so we need to move up */
                System.err.println("Moving " + e.getText()+ " " + after.getHeight() + " up");
                //e.setY(e.getY() + after.getHeight());
                e.setPosition(e.getX(), e.getY() + after.getHeight());

I found out that the last element of that list is always at y=16. I can set it in this iteration to like 45 but in the next call it’ll be 16 again.
Note: This means it gets set to 45 but the getY() is 16 again?

SOLVED: The Problem is, if you remove an Element out of a ScrollArea somehow the Position of the Last Item gets messed up. The Solution is to perform the upper code (but remove the clicked item out of the list) and remove the item afterwards from the ScrollArea

Does noone have a solution?
I mainly look for a way to use tonegods InputManager to hook keypresses sent to a specific window?

There is no such method as onKeyboardPress (the KeyboardListener is for the textfield and other) you have to come with you own solution by registering a key to the inputManager etc…(wiki inputManager), as exemple you can extends the window to handle it.

As side note, an element is not a spatial, casting is not allowed there, you picked the wrong children method, you need to use “getElementChildren” and not “children”.
If you iterating over all children you can use the elementID to get the needed children (if doing so you need to know the id of the needed children, when creating an element you can give them a custom ID)

About the alignement you need to use the layout system or come with you own solution, i can’t explain the layout system as i’ve never used it and it is one of the last added feature.
thread on layout
for some exemple try : test case project

My problem is that tonegod seems to block/unhook my inputManager-Keys, like usually ESC quits the app but when my ChatBox has the focus, it does not.

Is there something like screen.getFocusedElement()? I think I should dig into the SourceCode to find that internal inputManager.

The other thing is solved by now, I found out that I need elementChildren. So you say if I used the Layout-Feature it would’ve worked automatically? Might come in handy for more complex guis.

Thanks for your reply :slight_smile:

Tonegod has his own key registered (if i can call that registered key as it isn’t realy that), mainly used for all stuff concerning text. That why the ESC doesn’t exit the application when having the focus on a textfield.
I don’t realy get what you realy want, if you want the application to quit when pressing ESC even when the textField have the focus just override the method onKeyRelease of you textField or chatBox (idn what you’re using) :

      public void onKeyRelease(KeyInputEvent evt) {
                if (evt.getKeyCode() == KeyInput.KEY_ESCAPE) {
                    // This trigger when the user press the ESC key 
                    // while using the textField or a class of that type.

If you need the focus of an element, if i remember well there is no such method as screen.getCurrentFocus() but each element got a methods called “setHasFocus(boolean b)”, this method trigger “localy” each time the element get the focus or lose the focus. So if you want the focus over you textfield or chatbox (or idn) just override it to do do whatever you need, don’t forget to call the super.

What I want to achieve: “Making the GUI usable without a Mouse (To support controllers)”.
Essentially that only means: Calling hideWindow() on an ESC Press on the currently active window.

If I got it right, I have two cases:

a) A textBox/InputField which bypasses jme’s inputManager → Solution: Override onKeyRelease
b) no textBox active which means jme’s inputManager gets triggered → Solution: keep track of currently focused window by overriding setHasFocus

You get the idea. But setHasFocus only trigger with the mouse, and following you last statement it seam that you didn’t use the mouse : “Making the GUI usable without a Mouse (To support controllers)”.

Without using the mouse you can still have the focus but you’ll have to do it manually by having a focus manager who will call the method “setHasFocus(true)” to the needed element and “setHasFocus(false)” on the previous element.

I got the time to work on a) now.
I tried to override the ChatBoxExt but it leads to some trouble because the ChatBoxExt relies on private variables.

For Instance I can’t reset the tfChatInput (private), I can’t access sbDefaultChannel (private) or the sendKey. Actually only the first one is a problem to me as I can get the other’s by overriding setters.

What would you do in that case? I could “copy” the ChatBoxExt Code and don’t have it derive from ChatBoxExt but that sucks if t0negod would release an update.

The clean way would be to fork it and have an own custom build but that would make everything more difficult and I guess tonegodgui won’t update so frequently.

Is the Google Code one the most recent?

Hi again,

the chatBox is a panel, why not simply get his child as they are public, ex :

 // to get the tfChatInput TextField use :
tfChatInput = myChatBox.getChildElementById(myChatBoxUID + ":ChatInput");
tfChatInput.setText(""); // clear the textfield

if by “sbDefaultChannel” you mean “spnChannels” this one in the source i have is never used, neither instanced. i don’t get the point to access it, even if you could.

Yes the Google Code is the most recent one, sadly there is no “public” news of tonegod on the forum since a while…
Maybe someone should take care of her project the time she came back, at last for bug-fix, well, that’s another subject.

Let me know if it worked, i’ve didn’t tested the code above so… xD