Search code examples
javalibgdx

TextButton LibGDX only clicks once


I'm coding a libGDX application that uses a button. The button looks like this:

TextButton btnPrint = new TextButton( "Print", skin );
btnPrint.setClickListener( new ClickListener() {
    @Override
    public void click(Actor actor,float x,float y )
    {
        System.out.println("Printing...");

    }
} );

When I click the button, it prints"Printing..." as expected, however, if I click it again, it does nothing. How can I fix that?


Solution

  • Out of my head but try:

    btnPrint.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y)
        {
            System.out.println("Printing...");
        }
    });
    

    Everything used here comes from the LibGDX library so import the correct classes. Perhaps you are using vis-ui, AWT, JavaFX or anything else? I find it mysterious that your code is compiling correctly.