Adding a TextEditor to the wiki fenggui tutorial

i’m trying to add a TextEditor to the following wiki fenggui tutorial (http://www.jmonkeyengine.com/wiki/doku.php?id=fenggui_jme_appl_using_standardgame)


        TextEditor tf = FengGUI.createTextEditor(window.getContentContainer());
       tf.setEmptyText("Enter Some Text Here...");
       tf.setSize(200,26);
       tf.addTextChangedListener(textListener);



it loads. but when i click the mouse inside the TextEditor i get this crash:

SEVERE: Main game loop broken by uncaught exception
org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
   at org.lwjgl.opengl.Util.checkGLError(Util.java:56)
   at org.lwjgl.opengl.Display.swapBuffers(Display.java:555)
   at org.lwjgl.opengl.Display.update(Display.java:571)
   at com.jme.renderer.lwjgl.LWJGLRenderer.displayBackBuffer(Unknown Source)
   at com.jmex.game.StandardGame.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:613)



ideas?

hiya, cool it would be nice if the FengGUI tutorial would be a bit more complete.



When i added a TextEditor with an empty textListener, everything i got no errors.



        tf.addTextChangedListener(new ITextChangedListener() {
            public void textChanged(TextChangedEvent textChangedEvent) {
               
            }
        });



Do you do something funky inside you textListener?

nothing weird i don't think… here is my full code:


TextEditor tf = FengGUI.createTextEditor(window.getContentContainer());
tf.setEmptyText("Enter Some Text Here...");
tf.setSize(200,26);

tf.addTextChangedListener(new ITextChangedListener() {
   public void textChanged(TextChangedEvent textChangedEvent) {
      System.out.println("hello world");
   }
});



and i get the OpenGLException.

This works fine for me (once I fixed some of the erroneous code)



 TextEditor tf = new org.fenggui.TextEditor();
                    tf.setText( "Enter Some Text Here..." );
                    tf.setSize( 200, 26 );

                    tf.addTextChangedListener( new ITextChangedListener() {

                        public void textChanged( TextChangedEvent textChangedEvent ) {
                            System.out.println( "hello world" );
                        }
                       
                    } );




Although if you use StandardGame you may need to do this:


        GameTaskQueueManager.getManager().update( new Callable<Object>() {

            public Object call() throws Exception {

                try{
                    TextEditor tf = new org.fenggui.TextEditor();
                    tf.setText( "Enter Some Text Here..." );
                    tf.setSize( 200, 26 );

                    tf.addTextChangedListener( new ITextChangedListener() {

                        public void textChanged( TextChangedEvent textChangedEvent ) {
                            System.out.println( "hello world" );
                        }
                       
                    } );
                   
                    disp.addWidget( tf );
                } catch( Exception ex ){
                    Logger.getLogger().log( Level.SEVERE, null, ex );
                }

                return null;
            }
            } );


cool thanks, that fixed the crashing i was having.

Glad I could help :slight_smile:

hmm strange that it sometimes works and sometimes not :frowning:



I guess its best to create all FengGui widgets in the OpenGL thread, i'll change the wiki entry.

doh, but this is already the case in the wiki :wink:



l—l: i guess in your case, you didn't create the FengGUI-GameState in the OpenGL thread?



From the Wiki:


        // Make sure the FengGUI GameState get created inside the OpenGL Thread.
        try {
            GameTaskQueueManager.getManager().render(new Callable<Object>() {
                public Object call() throws Exception {
                    FengGUIGameState fengState = new FengGUIGameState();

correct. here is the full code that runs correctly for me. 



is it me, or does fenggui have poor support for text box interaction? i.e. double clicking words to select, mouse drag to select, shift-arrows to select, option-arrow to skip forward and backward, holding down keys for repeat, etc. but i guess that's a post for the fenggui forum, not the jme forum :) 


GameTaskQueueManager.getManager().update( new Callable<Object>() {
   public Object call() throws Exception {
      try{
         TextEditor tf = FengGUI.createTextEditor(window.getContentContainer());
         tf.setText( "Enter Some Text Here..." );
         tf.setSize( 200, 26 );
         
         tf.addTextChangedListener( new ITextChangedListener() {
            public void textChanged( TextChangedEvent textChangedEvent ) {
               System.out.println( "hello world" );
            }                       
         } );
         
      } catch( Exception ex ){
         System.err.println(""+ex.toString());
      }
      return null;
   }
} );