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
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 cannot find one online and I am surprised there isn't one... but is there an online Java GUI Layoutmanager at least?
WindowBuilder for Eclipse is phenomenal. One of the things that awesome about it is that you can hand modify its' generated code and it will pick that up without a problem.
What do you mean by an online GUI builder? If you want one that's a webapp, it's not likely you're going to find one.
If you're looking for a GUI to build a GUI, I would recommend the Netbeans IDE. I forget where it is exactly in the IDE, but you can basically just do file->new->java-gui (or something of the sort) and you will get a very nice interface for constructing swing gui's.
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.
Is there a plugin that would allow me to design the GUI in eclipse or netbeans and then extract the source code to be used in another environment?
I am much more comfortable using emacs for my development but gui design is much easier with a WYSIWYG environment. What i am looking for is design the frame in eclipse/netbeans and then extract just gui code so i can import it to my project?
Like JFrameBuilderdoes.
What's wrong with using both Netbeans/Eclipse and emacs on the same set of files?
Use Netbeans or Eclipse to design GUI.
Close Netbeans/Eclipse.
Open Emacs and code away.
Close Emacs.
Rinse and repeat.
Personally, what I have experienced is that GUI design in Swing is best done without a WYSIWYG. I came into Java after many years of developing applications with Delphi, and at that time there was no suitable GUI designer for Swing, which was a bit of a shock for me.
In order for a manual UI design/coding to be efficient a really good layout manager should be used. MigLayout is one of such layout managers. Since I've started using it I have never looked back at WYSIWIG tools -- a sheet of paper, a pencil, MigLayout and a full control over your code.
I have just installed Eclipse 3.4 and found out that there is not a plugin to create Swing applications yet. I also have found that there is a Matisse implementation in MyEclipse IDE, but I'd like to now whether there is such a Matisse plugin for free.
Instatiations Swing Designer is the best in my opinion. We settled on it after trying may different Eclipse plugins.
there isnt one for free. myeclipse is the only way to run matisse inside eclipse.
Although this is not a true answer to your question, you may as well look at alternative solutions in terms of layout management: Matisse and GroupLayout are neither the only way, nor the best one, to define your GUI forms.
I would suggest you take a look at:
MigLayout (very powerful and quite
simple)
and DesignGridLayout (quite powerful
and very simple)
Both are open source and have a friendly license (not GPL).
A quick search on Google will give you the links immediately.
Disclaimer: I am one of DesignGridLayout both project owners, but I point you to it because I'm convinced it provides a better way to define Swing layouts.
I did a quick Google search and found that you could use Netbeans Matisse and Eclipse in parallel:
NetBeans Wiki: UsingNetbeansMatisseAndEclipseInParallel
It seems to basically involve building the Swing GUI in Netbeans and doing the other coding tasks from within Eclipse.