Editable Textfield on GLCanvas

Hi,

i need to display some editable text inside my application. jogl’s text-render-classes are cool, but i want to use the graphics of a jtextfield, because i need the cursor and textselection to be displayed. the result should be something like a 2d textbox, which is draw “over” the 3d scene. so i only need the real text from the jtextfield and not the other elements like border, background,… and all this should be running on java 1.4.2 (even if its slow)

i looked at the renderdelegate class and the texturerenderer class… but i didnt get it working jet. is it possible to just override the jtextfield’s paint method and draw its content into and textrenderer image or somethink like that? or is it possible to “extract” the formated text from the jtextfield and render it using the TextRenderer?

This is a good question. You should be able to manually invoke the JTextField’s paint() method passing in the Graphics object obtained from JOGL’s TextureRenderer to get it to draw its contents into it. However, as you’ll quickly find, event dispatching won’t work, for example.

We’ve been thinking a lot internally about providing something like a Swing component overlay for any GLDrawable that would do the appropriate event re-dispatching and draw the Swing graphics to the screen via OpenGL, but this is a little way off at this point.

For the time being, can you use a heavyweight component to wrap the JTextField and a null LayoutManager to explicitly place it on top of your GLCanvas?

The other alternative would be to implement your own text area in JOGL using the TextRenderer and the ability to change the text’s color – you’d need to figure out how to map mouse clicks and drags to figure out what text is selected. Probably not impossible with the APIs that are there currently, but may be a little tricky.

hmm… i’ll solve this by using an extra dialog, where the usere can enter his text. after closing the dialog the text is render via textrenderer. this seems to be the cleanest solution, but by far not as comfortable as “in-place” editing.
all this swing event handling made me go crazy :frowning: one of the main problems is focus handling, i think.

implementing your own textfield with TextRenderer isn’t that hard. there are very useful classes in the java.awt.font.* package that help you with positioning your cursor and selecting text etc.

thanks, you are right… i’ll give it a try. The TextLayout class seems to be the thing i’ve been looking for.
http://www.cs.wisc.edu/~cs368-1/JavaTutorial/jdk1.2/api/java/awt/font/TextLayout.html

Some time ago, I also tried some tricks to render swing components in space. I delegated (transformed) events of the GLCanvas to the swing components, painted the component to a BufferedImage and rendered it as texture on a quad. It worked not for all components (all “overlays” like JComboBox werent painted properly) but it was good enough for debugging purposes (I used it to render more or less interactive debug information in world space).
It seems like the JMonkey devs used a similar approach, at least JComboBoxes are also not working in the webstart demo :stuck_out_tongue:

I cant wait to see a clean implementation of this feature in JOGL. ;D

If you don’t want to do the work yourself, there i the fenggui package, which has worked fairly well for me. http://www.fenggui.org/doku.php