Search code examples
javaswingapidrawingprocessing

Any Java drawing API similar to Processing?


I've been working with Processing for quite a long time now and I pretty much know how it works and how can I exploit it to get what I want every time. The problem is that I'll be probably starting a high caliber project soon and I don't want to be hardcoding things like buttons or sliders manually via Processing while Java APIs (like Swing) get the work done in a hurry, drag&dropping.

Given that I've never joined Processing and Swing, and hearing people say that those two doesn't work well together, maybe someone can put a light on my future by giving any tip of a library that works like Processing (in terms of easy drawing methods) and combine well with Java, so it would be easy to code a "premade" part consisting on tables, buttons, sliders, yada yada... and other we can call "visor" where the graphics are drawn upon user actions with the controls.

I could try to explain myself better if something was not understood, but there must be someone (I hope at least) that knows about a graphic lib easy to bind and use with Swing. Thanks in advance!


Solution

  • Note: I wrote this answer back in 2014. Since then, much of this has changed in the latest versions of Processing. I'm going to leave the answer here for posterity, but if you're reading this after 2020, it likely no longer applies.

    I disagree with the other answer, so I'm going to post my own.

    First off: you can absolutely mix Swing and Processing, as long as you use Processing inside of Swing. Using Swing inside of Processing is the part that doesn't work.

    Secondly: Drag-and-drop GUI builders are notoriously horrible for Swing. For the love of Gosling, stay away.

    Third: JUNG uses Swing, so it's not really an "alternative" to Swing. It's on top of Swing.

    Fourth: You said you're going to be using Java, so pointing out JavaScript solutions seems to go outside of the question.

    All of that being said, you can absolutely use Processing as a Java library. You can mix it with either Swing or JavaFX, as long as you're putting Processing inside of Swing/JavaFX and not the other way around.

    A Processing sketch is an AWT component (AWT is the GUI library that was around before Swing). Specifically, it's a subclass of Applet. You can put an AWT component (including your sketch) inside Swing or JavaFX just fine. The problem is when you go the other way: you can't put, for example, a Swing JButton inside of a Processing sketch. Going the other way (which is what you want to do) is fine though.