Java Swing : Write cross platform application (basically CRUD) - java

I need to write cross platform application (basically CRUD).
Is usage of Java Swing good idea? Or is it out-dated and you know better solution?
I dont want to use like 5 languages for various stuff, one or two should be enough.

Java and Swing will absolutely fit the requirement, and you will be able to make do with just the language runtime as downloaded from Oracle/Sun and nothing else. Java is one of few languages that comes with a complete and powerful GUI library of its own already included.
If I were to write a program like this these days, that's what I'd use.

Swing is complete, maintained, well documented, and implemented in Java, ensuring cross-platform portability. Most relevantly, it's part of the Java language so no other downloads for the user to manage / bloat your program.
Although the default look and feel is ugly, Java 7 is to update the default look and feel of Swing to Nimbus, which looks very glossy.
If your question relates to using the language itself, I'd say "yes". Java is, like Swing, well documented and highly developed. It may seem verbose but if there's a problem, you can sure tackle it in Java.

Personally, I've always much preferred the Standard Widget Toolkit in terms of GUI toolkits myself.
Some argument and discussion.

Java/Swing will definitely do what you want. There are other solutions such as .NET/Mono, Various cross platform GUI libraries and C++.
If I had to decide today which to use it would be Java/Swing. Java because it is better supported, Swing because it's built in and JDBC simply tips the balance away from the others.
Gavin's right +1 for the SWT. If I didn't already know Swing I'd consider SWT before making a final decision. However I do know that Swing does the job well.

Since both good java answers are already given, It should be possible to do the UI in c# as well (as long as you don't use anything Windows specific). System.Windows.Forms type applications can run on Windows, linux and Mac OS X (with mono). It does require a bit more work to get the packaging done for each platform you want to support, but it is possible.
(If you already know java you're still better off using that though as the support is better across platforms and it doesn't require your users to install mono or .net)

Java/Swing is fine. I would recommend getting a license for JFormsDesigner or one of the other UI layout tools that makes life much easier.
Also, check out SwingX which is people who work at Swing making custom controls and what not that look good and are very useful.
That's also a good place to look for best practices.

Maybe you can decouple the front end from the back by creating XML request/response streams and using web services. Then you can write the front end in whatever technology you want, as long as it uses an appropriate web client.

Related

Java Swing for Web Development by converting to Javascript

Good day!
With regards to my previous question about Java Swing being used for web development, I have a job interview today and they told me that their company uses Swing then convert it to javascript then deploy it on the web.
Can anyone explain this to me better? What books / websites should I study so that I could understand how this is done. Is this a good / common practice?
Thank you very much.
You can take a look at CreamTec's AjaxSwing. I've played around with it several times and it's the only product I know so far that takes your existing Swing GUI and converts it into something displayable in your browser.
Whether this is good practice or not is not really easy to answer. This solution works well as long as your application does not need to scale largely. CreamTec states that their solution is suited for about 50 clients IIRC.
The markup generated by AjaxSwing can in no way be called semantic but that is a common thing with these kinds of generators.
You can try AjaxSwing pretty easily since it does not require you to do much configuration but my recommendation is to use a dedicated web framework if you want higher scalability.
It sounds like GWT also. Granted that is not what the person said, but if it was a recruiter, they may been confused on the exact technology.
AjaxSwing is a run-time tool and needs a server license for commercial use.
You might want to try Mia Transformer www.mia-software.com. They change Swing Java code to GWT Java Code and GWT changes it to Javascript and then if you want you can use Google V8 compiler for faster execution. Of course it is not 100%. We are going to try it for a large project and see if it works.
The other link provided to us was http://swingweb.sourceforge.net/swingweb/. Have not checked it out though.
Will keep you posted. If you come across a workable solution please share.

Java vs. C++ for building a GUI which has a C++ backend [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I currently have a C++ backend that I need to connect with a GUI, and since I've never built a GUI before, I was confused on where to start.
I'm comfortable writing code in C++ and Java, so I'd prefer my GUI to be in one of those languages. Also, the GUI has to be reasonably OS independent over Windows and Linux (and hopefully, hence Macs).
Now I understand that if I use Java to do it, I'll need some wrappers to do it - but I've also heard (strictly second hand) that writing a GUI in C++ is a pain.
I don't want to rewrite too much of my backend code in Java (who does??) and I was hoping for input on:
Does either language offer serious advantages/disadvantages compared to the other?
How serious is the wrapping issue, and how much rewriting would come in if I used Java.
Are there any specific resources I should look at that people think would be relevant?
Thanks and Cheers All :)
Have a look at Qt.
In my experience communicating between two different language runtimes is always challenging. If you have a non-trivial application to build the following often pose challenges:-
Error Handling.
Memory Management.
Multithreading and Synchronization
Semantics.
Apart from increasing one level of indirection due to wrappers, it requires a lot of thinking like circumstances where you need to pass data structures across GUI and backend etc.
For example:- Consider passing a Java String from GUI to backend C++.
Essentially, we have to extract the characters from a Java String object and make them available to the C++ developer without leaking the memory which holds them. This is an example of a basic problem (there are other aspects too like the encoding in which the characters are to be returned).
You say you already know C++ and Java, and that you never did a GUI before. That means:
no matter if you go for a Java GUI or a C++ GUI, you will need to learn how to handle the GUI framework
if you chose Java, you also need to learn how to interface between the two languages
So staying in C++ saves you one thing to learn. Well, it's always a good idea to learn something, but might be a bad idea to learn two new concepts at the same time. Anyway, the learning might be the smaller burden, I guess there is a lot of actual work involed, even when you use tools like SWIG.
You might want to know if writing a GUI in Java or doing it in C++ is easier. It depends on the chosen Framework. For Java, you have AWT and Swing which are part of the default Java distribution, and then there is SWT which is used by Eclipse, for example. For C++, there are many toolkits, with Qt, GTK and wxWidgets being the most popular ones, and all three support every major platform. Most of those "C++" GUI toolkits also have a Java binding or even a Java port, so you could use them with Java as well.
So far I've used Swing, Qt and a few others which don't help in your situation (The UI thingy that came with Borland C++ Builder and WinForms on .NET). Basically, the concepts are the same for all those frameworks, and I found none of them being harder or easier than the other. The only exception maybe Java, because I never got those LayoutManagers to work, even though the other toolkits have equivalents to LayoutManagers that are easy to master. But maybe thats just me.
People also will tell you that Java GUIs are always ugly and don't fit the host system. Well, most Java GUIs really are, but IMHO thats not because of Java, but because of bad programming. It takes two lines of code to let a Swing app adapt to the look and feel of the OS, and most programmers simply don't put enough effort into their Java GUIs to copy and paste those two lines... you can imagine how much they care about the rest of their GUI design.
For your current situation, I would recommend a C++ GUI, but if you know how your future plans look like, and if you know you will doing Java GUIs for the rest of your life, then it's probably ok to start that now and take the extra effort of .
And if you chose C++ for the GUI, people will tell you all kind of things to pull you in any direction. All of the three big portable frameworks have their pros and their cons, but I don't believe there is any single best or worst one among them. I'd recommend Qt simply because I already used it - but if I'd happten to have used GTK or wxWidgets instead, I'd probably suggest that.
Depending on your needs, a simple web interface might be the simplest when you have no existing frontend code. Embed a tiny web server in your application and open a browser on "http://localhost:12345" (or what port you end up using).
I can't say much about coupling Java and C++, but I suggest you have a look at Qt.
It's a C++ library for a lot of things, like file and network access, but it's most famous for GUI development. It also has a nice IDE were you can build your GUI with drag-and-drop.
I would also say that Qt is as OS-agnostic as it gets for GUI libraries.
Writing a GUI in C++ is no more of a pain than doing it in Java.
There are numerous cross-platform GUI libraries. GTK, gtk--, FoX, WX, etc. I would not recommend Qt since it's not really C++ (uses an extended version of the language requiring a special preprocessor before compilation). Plus it costs a fortune if you don't want to give away your product.
BTW, that's not how the word "hence" is used.
You did not mention the richness of the interaction between front and back ends, which would weight the importance of the existing language in your decision.
I've worked with Qt, Swing and SWT, and typically used both C++ and Java code with all of these toolkits. The interaction between languages can add additional cost/risk. However, sometimes that cost is warranted given other benefits.
If for any reason you choose a Java front end, look at JNA and SWIG.
Let's all be honest here. C++ just ain't on the map when it comes to portable GUIs.
Java has a consistent, portable, widely used, thoroughly documented, mature GUI toolkit. C++ has a bunch of half-assed OSS libraries that barely work, none are truly portable, plus some expensive commercial libraries that don't work on all targets they claim to, work spotty on the remaining targets, and invert control so that you are stuck in their weird framework.
Unless you need C++ for other reasons (of which there are plenty), choose Java for the GUI. The cross-over coding is trivial for someone who knows both languages, but it can get messy to manage, so you'll want to minimize the native interface as best you can. My advice here is to make a pact with your team that you will never attempt to hold pointers (or references) across the interface. It just gets messier if you do, and no debugger can save you when the lines get tangled. Instead, use integer or string keys and pass them across the native interface.
How about eclipse? Looks good and performs well on all platforms. My guess is most of eclipse is Java.
Why you don't you learn native C++ GUI like WINAPI or X11? Then you can make console software to compatible one of them like winehq, cygwin or other open sources compatibility or emulated software, since you never developed GUI on C++. Don't go for Java because it uses much more RAM. Of course, unless you have lots of RAM. For example, Eclipse (which is coded in Java) can use 500mb of RAM when running with no project opened.
Wrapping is not rewriting, it's just an adapter to make both languages meet. It is straight-forward
As you don't seem to be fixed on a language, I would choose a .NET Gui (With C++ CLR) you'll have a GUI that is machine independent and you can easily communicate with your existing code.
For beginners WinForms is maybe easier, but try to use WPF, it's the most modern variant for GUI development in the .NET world.
Personnally I would use C#/.NET for the GUI and use a C++ CLR wrapper DLL. But it is not the only solution.
Under Linux, the best .NET implementation is MONO. For all WinForms apps I have developped (they are not the craziest ones), they ran without change. With C++/Qt you will have to recompile for each target OS.
Do not use Java for creating GUIs unless platform independence is a must. The user experience will be sluggish and interoperability to C++ will be a pain.
For creating native GUI in C++, you can either use GTKmm along with a library like Boost or QT. Additionally, these libraries are available for most platforms (GNU/Linux, Windows, OS X) so your application can be recompiled anywhere.
edit: use GLADE for quickly creating GUI and fill in the signal slots with C++ code in GTKmm.

What to use for writing a user interface?

I've written a series of classes to interperet data from a serial port. This data needs to be displayed on the screen. I am trying to go for straight up eye candy with a refined look.
Swing UI- Easy to program, yields mediocre results
Open GL- Hard to program, yields good results.
Are there any other options?
Give SWT a go, the API is a lot simpler than Swing. Here is a recent question outlining the differences between SWT and Swing.
I'm not aware of any alternatives, but in my opinion it is possible to write beautiful GUI with Swing. Just changing the ugly default look and feel goes a long way. Visual appeal just doesn't seem to be a top priority for most Java coders and therefore you have to make an effort to make anything pretty.
JavaFX maybe? Didn't tried it yet, it obviously offers some eye candy.
You can use NetBeans combined with JOGL (Java bindings for OpenGL) or simply with Java2D.
NetBeans has an easy GUI Builder for Swing applications -- you can make beautiful interfaces (if you get into it), easily change the Look&Feel, etc etc.., and you can use Java2D or JOGL for visualizing your data and embed it in the GUI to display it.
There's a plugin for JOGL for NetBeans so getting started is hassle free.
use html, css, javascript. Much easier to get wizz-bang UI than using Swing or related technologies.
For my projects at work, we have purchased a licence of JFormDesigner.
This is really a great tool that saved us a lot of time.
Writing Swing application by hand can be a real pain and is awful to maintain.
This tool choose the right approach : The model-view-controller.
The GUI builder creates XML files for you that represent the interface. These XML files are loaded at runtime and transformed into Swing objects. The builder also generates Java stubs that you can fill with event handlers.
It also handles Localization and nice layout goodies.
Give it a try.

Good-looking Java Swing Look&Feel?

I'm working on an open-source Java Web Start application, and I'd like to give it a consistent theme across platforms. Metal is totally ugly, and I'm not particularly happy with Substance (esp. performance). What are the best Swing Look&Feel options out there today?
I like the 'Nimbus Look&Feel'(2nd image) introduced in Java 6 Update 10 very much and it is contained in SUN's vanilla J2SE of J6u10 and later by default!
Another advantage is, that it is painted entirely using Java 2d which makes it fast and rederable at all resolutions.
Check out JGoodies, its the de facto standard place to start for a decent L&F.
I have found that using the "native" L&F consistently results in applications that look "right" for the specific platform. But JGoodies is an excellent across-the-board alternative.
For myself, I don't care if an app looks "native", as long as it looks just as professional and at least as good. FWIW, I don't think the that Java "Metal" or "Ocean" looks achieve either one.
That said, be careful... for many users the only thing which will look "good" is that which is the same as every other application on their platform. The only UI that I think consistently trumps all for looks is the current Apple OSX look - but even that looks out of place when it's the only such app in my Windows desktop.
javootoo has a nice compilation of swing look and feel packages, with screenshots.
The Alloy Look and Feel is pretty good IMO, but it costs $$$
http://lookandfeel.incors.com/

Where are Swing applications used?

Are Swing applications really used nowadays? I don't find a place where they are used. Is it okay to skip the AWT and Swing package (I learned a bit of the basics though)?
If you are writing for the web exclusively, you can probably skip Swing, but otherwise you're absolutely going to run into it. I've never worked on a non-trivial Java app without a Swing GUI.
Also, Swing is one of the better APIs to use. If you use most others, you are going to find them more difficult to use and/or platform incompatible. (If anyone reading this is aware of exceptions to this, please leave comments, I haven't looked for a while and am kind of curious if anything better has become available)
Other JVM languages like JRuby and Jython are often used because of their access to Swing.
You may checkout Swing Sightings.
This website is hosted by SUN and it is dedicated to sw projects that use Swing.
There are a lot of projects using Swing ...
http://java.sun.com/products/jfc/tsc/sightings/
Swing is heavily used in business specific (vertical)/internal application development.
Hmmmm... how about NetBeans? You know, the IDE? It uses Swing.
Swing applications are used in most cases where a Java app runs on the desktop. Sometimes you don't even know - for example, LimeWire is a Java Swing application.
When learning Swing, you'll find that you will come to know those parts of AWT that are still important, such as Event, LayoutManager, Graphics, Font, Color, etc.
You should certainly write Swing for desktop Java, only using AWT to the degree that Swing demands it.
I'm sure people can come up with examples of very good Swing apps besides SQL Squirrel and IntelliJ.
I think that RIA technologies like Flex, Silverlight, etc. are ascendant because the web and services are taking mindshare from desktops. It's not just Swing that's losing out.
Whenever you want to write a desktop GUI app for non-Windows OS, you use Swing as the only sane and guaranteed cross-platform GUI framework.
Besides, Swing has a very good design. I recommend to learn it anyways, to make yourself a better programmer.
Check out Filthy Rich Clients. It explains some of the history of AWT and Swing. Swing, being a lightweight alternative (successor) to most of the AWT classes.
IIRC jEdit is also a Swing app. Quite a popular text editor.
Skip AWT and Swing? To jump where? SWT? Web-based development?
In the broader sense, I have a number of Java applications, although I am not too sure if they use Swing or SWT.
Lot of database tools like SQuirreL SQL Client are written in Java. I think SQuirrel uses stuff from Netbean, which is, of course, Swing based.
yEd is written in Java, probably Swing.
A number of P2P softwares are written in Java, including Frostwire (I see no trace of SWT there, but I can just miss it).
And this list is far from exhaustive!
Lol! I forgot to mention the software suite made by the company I work for! It is quite specialized, used by mobile phone companies to monitor health of their network nodes (superficially looks like a spreadsheet). Totally Swing based.
While Swing has some cross-platform look-and-feel deficiencies and it would be nice if it was updated to support generics, it is still well designed and quite usable. I have always been a fan of the sheer amount of customization offered. SWT is nice and is more native, but you give up some power and control with that as well. In addition, it seems simpler to use, which can be a plus, since Swing can be overly complex due to its flexibility.
Geertjan Wielenga often blogs about applications based on the NetBeans platform, and therefore Swing. The applications range across the board from rather small esoteric applications to very large, mission-critical systems (Boeing Aircraft comes to mind). Many of the enterprise-level applications that Geertjan misses are mentioned on Planet NetBeans. It seems like every few weeks there is an announcement or description of such a program.
As noted above, lots of tools use Swing including the IntelliJ IDEA IDE, a favorite. I'm surprised no one else mentioned it.
Sun also used to maintain a Swing Sightings web site, but it hasn't been updated in a few years.
Where I work, Swing is used in the presentation layer for a very large document management system. In my own development experience I've used Swing for desktop applications in the areas of image processing, device control (video, motors, etc.), math, statistics, and medical devices.
BTW, I agree about the slowness of file choosers. But there are lots of alternatives that will use the native file chooser. It can just be a bit jarring if the L&F's don't match up very well.
EDIT: Oh, and as others have mentioned, it's very easy to use Swing from other languages on the JVM. With Clojure, for example, it is even easier to use than in Java, in my opinion.
There is no universal question to whether it is ok to skip something or not. It's a matter of priorities. While Swing has a lot to teach you (and it is too heavily infused with AWT), if you're never going to be writing GUIs you may be better off investing in something else.
Swing, while ugly as hell, is still used in many places. A quick search on "java swing" in Indeed or dice would reveal many jobs and industries that require it.
Are you skipping it for an exam/interview? Besides really good apps like IntelliJ IDEA and NetBeans, there are lots of Swing like frameworks [SWT (Eclipse), GWT etc.] which you can learn faster with Swing knowledge...
You should probably be looking at JavaFX for future work. As the FAQ states,
Sun is not replacing Swing with JavaFX Script. Instead, JavaFX Script makes Swing easier to use.
Using/learning it will give you a very good understanding of the important Swing concepts, and how they fit in with "the future". I haven't used JavaFX yet, but heard very good things about it.
Armitage tool is made in swing , GUI tool of metasploit framework.

Categories