As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I know how to create the basic controls in Swing, but coming to industry standard application development, I lack the skills to do them.
I am designing a small Java Swing application. Instead of creating a JFrame for each purpose, I would like to create controls, display them, hide them (whenever necessary), everything in just one window.
How can I do it? I am a beginner. Please point me to nice web resources on the conventional ways of doing desktop Java applications using Swing.
I'm not sure where I read this (old article), but since I read it I use it in all commercial desktop applications I make.
First thing get NetBeans, it's the perfect IDE for Java UI design. The other Eclipse plugins are not as helpful nor powerful.
Here is how I do it.
In NetBeans, create a new Java project — let's call it MyComponents in this project — create all your components you want. The base of any component should be a JFrame or a JPanel. For this example we'll choose JPanel and call it mjPanel
Next in the Design view, drag and drop all the Swing components you want. Then from the Source view, make all the actions and logic.
Next, the most important step, right click your Java file, from Tools, choose Add to Palette, then in the dialog, choose where you want to put it, like say Swing Components Palette.
To finalize your component, from Build menu, choose Clean and Build, this will create you a Jar file in the project folder/dist.
From now on, in each project you want to use this component, just include the Jar file in your project classpath.
Open the Swing Components Palette, and you will see your new component.
Like this:
I suggest you use NetBeans and create a project using the "Swing Desktop Application" pre-existing template.
It will create the basic infrastructure for your app including a main window with a menu and status bar with a progress bar, about box, event handlers, etc, all pre-wired.
What's nice about it for example is that the progress bar is already configured to listen to any action task that you create, so by simply creating a new action task, you get a working progress bar that will run when the task executes, without having to code it.
For more info see here.
This is the most-read tutorial on Swing without a doubt. Run through the tutorial from beginning to end if you have time, to learn the Swing way of doing things.
At the same time, try to locate a copy of JBuilder to see the template code that it creates for Swing apps. You will code by hand using Eclipse or whatever, but JBuilder can show you some standard ways of doing things. If you can't get a copy, check out some of the Swing plugins for Eclipse. In all cases, try to keep in touch with the code yourself: most UI editors are only helpful in the suggestions they give you.
Run through the tutorial suggested by yar. I'd also recommend the excellent book, "Filthy Rich Clients" by Romain Guy and Chet Haase (two big names in the Swing world). It'll teach you to make apps that look great.
I haven't worked with it much, but the Griffon project is attempting to standardize the MVC pattern for Swing applications. However, it's written in the Groovy scripting language, which then runs on the JVM.
Read a good book on the topic, such as Core Java or Professional Java User Interfaces.
JDock offers a docking framework, allowing you to present your application in a single frame, divided into separate dockable areas. I confess I've never tried it though.
Spring RCP is one, although risky solution. It has some nice features and in my opinion it works pretty well for the most part. However, the documentation is close to non-existing and the future of the project is uncertain. There are some users (including me) committed to RCP though, so it will probably not die completely.
The Java Look and Feel Design Guide offers a detailed reference about the standards in user interface design with Swing and metal look and feel. If you are planning to use this cross platform l&f, I definitely recommend you the reading.
Related
I need a new way to create the graphical user interface of my application. I don't want to use Swing. I'm looking for something that looks a little different. Can you recommend me some other way of creating it, please?
Why not JavaFX ?
It is supposed to be replacing Swing as the standard Java GUI builder, so it would be a good option as it will be getting regular updates from Oracle itself. Additionally, being an officially sanctioned kit, it has plenty of tutorials, guides, and a decent (and growing) userbase that you can use for help.
And it uses CSS, which is good to learn as it can be useful in other applications. (Webdesign, etc.)
Finally, JavaFX is included with Java 8, so you don't even have to worry about installing a separate package! (Although adding a package is really not difficult if you prefer Java 7 or below.)
If your complaint with Swing is how it looks, note that you can change the look and feel of a Swing application very easily, or even write your own if you really wanted.
To get a look and feel that matches other applications on your system, you call:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
At the beginning of your program.
The default L&F, called Metal, also has a couple themes you can choose from (or you can create your own):
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
Yes, javafx could be the way for you.
You can create Views using FXML files instead of coding everything in java.
The learning curve is not too hard in my view (and I am far from being a guru).
The tool Javafx Scene Builder is here to help you create your views or controls in FXML and integrates nicely with netbeans, and I suppose also with eclipse.
You can adapt the look of your controls using css.
I would suggest to start here to see if it would fit your need:
http://docs.oracle.com/javafx/2/overview/jfxpub-overview.htm
I'm a .net developer and I am studying Swing for Java and I have a question.
Is there any way to build the form controls by dragging and drop like a simple .net windows application project or WPF project?
I am using eclipse and it seems that everybody works with controls by adding positioning and width, height by code, I find that a pain in the a**.
Yes! Take a look at Window Builder for Eclipse (install it from the update site). Netbeans has also a built-in editor, if you prefer that IDE.
You need to install a plugin to do that.
In Eclipse you can try WindowBuilder.
In Netbeans this ability comes within the standard package.
Java's Swing framework tries to address a broad set of platforms, and it does this by separating out look-and-feel concerns, layout concerns, etc. The most painful part of setting up a form is the layout, and that is driven by the LayoutManagers.
There are various LayoutManager implementations built to be used in conjunction with form designer tooling. I've personally had good results with IntelliJ's designer. See some screen shots and feature listings here.
I would personally not recommend using any Drag and Drop builders. In some IDEs the generated code is not editable. Some IDEs allow you to edit the code, but the bottom line is no matter what IDE you use the generated code is very difficult to maintain. After a while you will find it difficult to work with it yourself.
Instead, since you are just starting out, I would recommend using a good layout manager right away. While we are on that, give the jdk's layout managers a wide berth. They are horrible and that's what causes most people to go in for the drag and drop solution. Instead try the Jgoodies Form Layout. Its very easy to understand and use. The link is here:
http://www.jgoodies.com/freeware/formsdemo/index.html
After you have understood that, try to give this builder I wrote a shot. It makes life even more simple:
http://code.google.com/p/swingobjects/source/browse/SwingObjects/src/org/aesthete/swingobjects/view/SwingObjFormBuilder.java
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Any good recent (Java 6+) Swing GUI builders the SO community would like to recommend? Some features I'm interested in:
Open source - great if its open but not hard requirement
Null layout managers - allow me to drag-n-drop controls where I want them
Custom controls
Design/Code split view or the ability to toggle back and forth
Thanks for any suggestions!
Netbeans is the best there is for Swing and will cover everything you need:
free,
open source,
null layout available, if you must use it... :-) ,
drag-n-drop,
custom controls you can drag-n-drop too,
great flexibility with files and projects and
refactoring.
They offer the best integration of Matisse Swing builder.
It is absolutely stable, expandable and fast.
There is a large number of plugins.
Hibernate reverse engineering is well implemented and there is a vast number of step-by-step tutorials that will help you start.
I personally use WindowBuilder Pro by Google. It is a plugin for Eclipse and it is free.
The next release of Eclipse - Indigo - will be on the 2nd of July and it will include WindowBuilder by default.
WindowBuilder is a powerful and easy
to use bi-directional Java GUI
designer that makes it very easy to
create Java GUI applications without
spending a lot of time writing code to
display simple forms. With
WindowBuilder you can create
complicated windows in minutes. Use
the visual designer and Java code will
be generated for you. You can easily
add controls using drag-and-drop, add
event handlers to your controls,
change various properties of controls
using a property editor,
internationalize your app and much
more.
Reference link: WindowBuilder Pro
I personally prefer to do everything by hand, it's more precise and avoid to get some generated code that is often ugly and dependant on a specific IDE.
NetBeans GUI builder is fine. You just need to save generated XML documents with GUI data, because it's not easy to edit the generated source code manually.
Thanks for your answers to my previous question about GUI in java. I now wonder what are the solutions chosen by professionals to get a nice GUI, for "real" applications. Do you use swing and JComponents and just change the "look and feel" ? Do you prefer awt or another library ?
Sorry if that question sounds weird, I'm a student and I don't really know how java is used in the real world...
In our company we use Swing, as that is supported by the JVM out of the box, but we do use color coded background colors for some panels and buttons.
If we'd use something different, like SWT or Jambi we'd also have to roll out those frameworks for all platforms, and test those frameworks for all OSses and (supported) java versions. Not nice at all.
It is however fairly tricky to create a nice responsive application with Swing; so you really need to use SwingWorker and the like. With a bit of experience however you can create a nice application that way.
And even if it isn't the fastest framework to develop in, development time is really small compared to defining the functional requirements of the user interface, and testing and support when the version is released.
That said, our target is desktops. If you target mobile devices or also need a web frontend your choices may vary.
I don't believe anyone prefers AWT anymore. Swing supplanted it entirely eleven years ago, building on top of it to correct flaws in the AWT 1.0 design.
Swing isn't the only way that professionals make Java UIs. That works for desktops, but there's also JavaFX now. For the web, UIs are built using HTML, CSS, JavaScript, and JSPs.
My experience is that most organizations that want to create rich GUIs still use Swing, and manually go through all the annoyances of layout managers, etc.
The use of SWT is fairly limited to organizations that are using the Eclipse RCP as their platform. I'm not sure why it hasn't caught on outside this platform.
It's sad to admit, but Java Swing GUIs don't generally look good unless you spend a lot of time creating a more native feel for them. Even then, they often lose out on aesthetics to equivalent programs written specifically for Windows and which use Window APIs like WinForms.
The most decent Apps I saw in the last years were build using Eclipse Rich Client Platform
Eclipse uses the Standard Widget Toolkit
and provides Graphical Editing Framework (GEF)
We typically use Swing becuse it's supported in standard JREs out of the box. Normally we do the initial form design and event hookup in Netbeans and then export it to whatever we wish, Eclipse, for example.
Netbeans spits out pure Java using standard libraries (plus a jar or two you have to include) so it's no big deal designing the form in Netbeans and later moving on to something else.
Some people suggested doing form layout by hand using a layout manager. I see that as an option only if you are doing something big and very well budgeted that has to be maintained ad infinitum. Otherwise it's just too time consuming to be worth it.
We rely on SWT for our Java GUIs. Yes, you have to include an external native library, but the look and feel is native, more responsive (although Swing has become much faster in the past few years) and seamless with other apps on the target platform.
Macintosh OS X creates their own Java runtime. They give Swing components the same look and feel as native applications.
I use strictly Swing. I distribute "real" desktop applications via Web Start for both Mac and Windows that interface with the user's smart card reader.
The NetBeans IDE gives you a WYSIWYG way to create your forms. I've tried it out, and it's pretty neat, but we still use Eclipse as our IDE and design the forms in code.
I need to create a GUI application in Java. I just realized that I have different optional ways to go (SWT and Swing are among them).
I have already found out that there is a lot of discussions about what way is better and I do not want to go to deep into these discussions (I am a newbie).
I do not care about all aspects of the dilemma. I just have a few main requirements listed bellow:
It should be easy to use (easy to create what I want).
In the end I would like to have just one file which can be easily executed (without any additional tricks, settings and installations) like a standalone application.
It should be platform independent. Or more specifically, the application should work fine on Microsoft-Windows and Ubuntu (Linux).
Based on your requirements, I would say Swing. SWT has a more platform-specific look about it but Java ships with Swing built-in, there's no messing about with external libraries as with SWT although the use of Eclipse may make that much easier (I still develop quite a bit of my stuff from the command line unfortunately).
They're both easy in terms of use (well, easy once you get used to layout managers) and will work fine under both your desired platforms but since the only differentiator you seem to care about is the "without any additional tricks, settings and installations", I would stick with Swing.
That's my advice. Feel free to accept or ignore or even call me an old coot. I won't take offence :-)
I just completed a two year project creating a buisiness application, so my focus was clearly on usability and speed.
My decision in the end clearly led to SWT, for the following reasons:
Buisiness users tend to use Terminal Servers and RDP for their apps. Every Swing app is very slow over RDP, because the app has to render every pixel again and again. Try using Photoshop or Gimp over RDP and start scrolling in an image. That is the performance you have with Swing in tables.
Some very good gui components are only available as COM objects. I wanted to be able to use those, and since 100% of all buisiness customers are Windows users, they accept the fact that your software only runs on Windows. (We have linux clients, too, but only for machine input terminals, that don't need the full blown Windows GUIs)
We use SWTDesigner as a GUI designer, which is as good as SwingDesigner für Swing (which both are the best GUI designers at all). They are worth the price tag if you have to create a few hundred masks.
Our GUI looks 100% native, honors the large fonts they use on their desktops, and feels fast.
We are very satisfied with SWT, but it has some downsides:
Native Java components are a bit rare. There is more on the Swing side of life.
I would suggest that you use Java's Swing libraries if you are not familiar with Java GUI development. They are very well documented, and there are lots of tutorials on-line, including on Sun's Java website (here).
GUI development in Java is not very straightforward, but the tools available are getting better all the time. I would suggest you try out the NetBeans IDE that has a nice visual designer for GUI components. I have not used the Eclipse IDE's GUI designer, but I gather its good as well. You will need to get your head around the MVC pattern, but it should be a good learning experience.
In short, my vote goes for using Swing/JFC, especially if you are new to Java GUI development.
EDIT - You can control the look and feel of a Java APP very easily. If you use the platform independent (Metal) look and feel, your GUI will look pretty much identical on Windows and on Linux. Of course, a Java app will run just fine on Windows of *nux as long as there is a supported JVM installed.
I cannot add comment yet because I'm new here (please mod me up so I can comment) but choosing Swing or SWT depends on the IDE you're using.
If you're using Eclipse, then both are fine.
If you're using the free IntelliJ IDEA community edition, you'll prefer to use Swing because the IDE's GUI editor is "Swing only".
I take it you're using Eclipse?
Based on your requirements, I recommend using Swing:
SWT requires additional native libraries (violates item #2),
You are likely to find more instructional material on Swing (since you are a newbie),
Both solutions are somewhat platform independent and supported on both platform you mentioned but SWT is not equally supported on all platforms,
There are more WYSIWYG tools supporting Swing which may help with the learning curve.
Note that the APIs are similar and sometimes identical so learning one gives you a head start on the other.
I find Netbeans' drag and drop visual editor and pre-wired Swing Desktop Application template much easier to use that what comes bundled with Eclipse, so I'd suggest that.
It'll automatically create an executable jar, and let you create a Java Web Start launcher if you wish as well. And being Java, it's OS-independent.
Here's a link to the quickstart tutorials.
Swing,
SWT works on Ubuntu but not nearly as well as on Windows, that's at least my experience. The main reason to choose SWT is if you want to build your application on the Eclipse RCP framework( where you get a dockable views/editors, plugin mechanism, automatic updates, user roles. help browser, preference mechanism etc) or if you want your application to have that polished native look.
From my experience, if you want easy to develop Swing is the way to go. If you need good performance, then SWT is a better bet.
NOTE: The last time I did GUI development in Java was 4 years ago.