# Menus for LWJGL - Swing or other? [closed]

Okay so I want to create a main menu which includes several buttons and text fields, is there a built in library for LWJGL or would I use normal Swing and start a thread of the application?

Its a 2D game and I'm simply looking for a way of starting it from a menu rather than having it jump straight into game.

As far as I know, there isn't a built in library for LWJGL, but there are several libraries using LWJGL.

I tried NiftyGui and TWL. TWL looks a bit easier and less messy to me, but both libraries need quite a lot of time to get used to work with (I managed to make some simple UIs with NiftyGui, with TWL we are stuck in the theme creation...).

If you only need buttons, you can make something pretty quick by yourself. But input text boxes (where the player can enter text) require some more work.

My advice would be: Check what you want to do. Do you want a complex or a simple UI. Does it need many different controls (sliders, checkboxes, comboboxes, textfield, multiline textfield, dropdown etc.) or only a few. If you have a complex UI with many menus, settings, editable controls etc. I would look at either TWL or NiftyGui, as both libraries are used by many people and work pretty well (if you set them up correctly). If you only need some basic things like buttons and a text menu, I would implement a basic UI by yourself, as it could take more time getting used to something like TWL or NiftyGui, then implementing the basic things from scratch.

As Peter Taylor pointed out, "Feng Gui" could also be an alternative. Though it seems to be discontinued, it seems to have a solid base: http://www.fenggui.org

• FengGUI is another option, although it's a couple of years since I used it so I don't know what state it's currently in. – Peter Taylor Aug 11 '12 at 8:15
• Oh yeah, I also read about feng gui, but never tried it, as it seems to be discontinued (last update on page is from 2009). There is a list of alternatives on the feng gui page. I add it to my answer. – tom van green Aug 13 '12 at 8:42

This might be too late for you, but for the benefit of web searchers, I'll answer:

1. Create an empty canvas (AWT).

2. Set the size of the canvas to be equal to the LWJGL Display.

3. Add the canvas to the Java Swing form. (There's a reason for this).

4. Set the canvas as parent of the LWJGL Display using Display.setParent(canvasName);. (Remember you might also need to allow the display to be resizable.)

The reason for adding the canvas to the form before setting it as parent of the Display is that, the canvas needs to be drawable so it can be a parent of the the LWGL Display. Otherwise your program will crash with an error that no OpenGL context was found.

This official tutorial is a good reference.