Nifty or Swing

I am not sure if it´s better to use nifty-on-texture&jmonkey or swing& jmonkey-in-an-canvas …

For example if i want to have an chat like in common MMO`s, and the graphic window is totally seperated from the gui… which way is better ?

is jmonkey in an swing gui with jmonkey-canvas slower then jmonkey with an nifty gui ?

thats an easy one! here is your solution → IT DEPENDS! :slight_smile:

2 Likes

atfer waiting nearly 3 days for any answer i´m really astonished by your wisdom ;D

This answer may not be much better, but I would definitely default to Nifty over Swing (particularly with jME) unless there’s some big show stopper using Nifty (“it depends”).



Swing can be a real pain when you need a highly customized look & feel (as with games), not to mention the boilerplate, and all the UI “stuff” in Java code. Swing was designed foremost for productivity apps, not games, and things like “focus rectangles” and similar standard stuff just get in the way in the case of games. Anyway I wouldn’t want to be bothered with Swing EDT issues, this stuff can get complicated enough without it.



In addition to the level of look and feel customization work needed with Swing, IMO Java code just isn’t the ideal place for UI layout. I’m certainly no fan of XML-for-everything, but for GUI layout it definitely makes sense. When I compare my Adobe Flex UIs (uses a form of xml, like Nifty does) to old Swing stuff, the clutter and unintentional obfuscation from doing this in Java becomes pretty obvious. The xml-format in that case actually seems to reduce the amount of code and text needed (contrary to many other usages of XML), and even better it allows you to visually understand component-container hierarchy relationships, which just isn’t so easy if you’re looking at line after line of Java code in a complex UI.

Also, isn’t there known issues with mixing heavyweight/lightweight components (which you’d probably be doing in this case if you use Swing)?

1 Like

@tebriel thank you so much for you informative post :smiley:



I just wanna make an simple amateur browsergame, and it doesn´t bother me, if it looks swing a-like …



Surely the code will be much more complex in swing, but for my little project i prefer an little bit more complex looking code instead of an much more complex programming effort to create the gui. After my understanding Nifty only supports an embed gui where the gui cannot be clicked which is an absolut no-go … so i will try swing …

No, you can interact with it fine - have you seen the demo? “TestNiftyExamples” in the TestChooser (try running TestChooser.exe or run the jMonkeyEngine3.jar as an executable). IIRC I think there is a mode of operation which doesn’t do interaction, but it’s not the rule. The demo is pretty impressive actually.

Although, if you’re talking about putting a 3d viewport and a UI right next to each other on the screen, where both can be interacted with at the same time (as opposed to the gui covering the entire screen)–I’m currently wrestling with this at the moment. I’m not sure if this is supported easily or not (which is odd because I think it’d be very common), so I may be starting my own thread for this shortly. (Still researching what the story is here.)

Got it - is a bit ugly since Application.initCamera() is private so I had to overwrite a number of fields, and I’ll have to spend some time cleaning up a little, but I think what you’re asking for does seem feasible without major hacking of the lib or anything.

  1. swing is faster than nifty by 500%, if you use it for out of game gui. For example warcraft 3 editor had only out of game gui. To edit units another irrelevant window was opened = you had to alt + Tab which sucks.
  2. Nifty is for ingame gui = gui on top of a 3d jme window. Nifty is easier to code than swing. In game gui is vital because for example you cannot have a health bar and ask the user to alt + tab to see that he has 10% hp.

well, vital parts are most suitable done with the standard HUD implementaion of jme, not ?! seems the easiest way for healthbars eg…



well i´m a little bit familiar with swing, and as i mentioned, i don´t need an real vital HUD or something like this, surely therefor swing would be wrong…, my game concept is comparable with games like Battle Isle or Civilization, but the game speed will be much more slower …so most of the game could be done fine with swing … i need jme only for some graphically improvements and additionall gui elements … like an info window with an animated modell of an unit or so… i dont need an action based game in real speed …



furthermore i´m not familiar with jme and i could not establish an clickable embed nifty gui…

Maybe this should be also explained in an tutorial, cause an clickable embed nifty gui should be an standard feature of nifty…

Well, there is a Swing Canvas section in the docs which talks about doing this, so I guess it’s do-able.



But I hear you regarding guidance using Nifty for various uses, in the short time I’ve been messing with it so far it has been a little too much “try it and see what happens” and not enough code-and-test by javadoc and example, but maybe I’m looking in the wrong places.



It sounds like in your case since your 3D usage is somewhat limited, Swing probably isn’t such a bad choice either, still assuming you don’t care about custom look&feel issues.

@tebriel well, i will try my best :wink: thank you very much for your efforts!

Funny, I’m probably going to settle on doing the same (Swing). After more through testing w/Nifty and jME, although in theory the design should work as I already started, but I just don’t think Nifty is mature enough yet. There seems to be some lacking functionality for what I need, and debugging and finding good documentation has been frustrating w/Nifty. I’ll just need to find a way to split the Swing code bloat off away from the core jME 3D code in a non-invasive way (so I have the option of a different GUI later on).



Given that your UI is probably going to be more complex than what I’m doing, I’m pretty sure Swing is the right choice for you at this point.