I need to compose a fairly simple GUI for a server monitoring process. It will have a few tabs which lead to a log tailing, counts of resources, and a start and top control. Nothing fancy here. Which Java framework, AWT or Swing, makes more sense for something this simple.
Swing is the way to go. It's a cleaner programming interface, and looks better.
Use Swing or SWT, since AWT has no tabs built in.
Starting with Java 6 Update 10, Swing got an entirely new look and feel, the 'Nimbus Look and Feel'. It looks great and is really fast because it uses vector graphics.
Swing is your best choice if you're stuck choosing between Swing and AWT.
If you have the flexibility, I would at least consider SWT. It's faster, matches the platform look and feel, and seems to have fewer porting hurdles and regression problems from release to release. There is a small hurdle in setting up your first project (getting the right jars and such), but other than that, it's no more difficult to work in.
AWT was the first Java GUI framework, it had a lot of flaws and was abandoned in favor of Swing. The main reason it is still in the JDK is for backwards compatibility and because some classes are re-used by Swing.
The future however (even for the desktop) could be JavaFX.
if you are planning to move your gui onto multiple platforms, then go with AWT. Otherwise, Swing gives you a much broader set of components to work with.
If you are looking for a better looking GUI, you can have a look at substance look and feel package in this address: https://substance.dev.java.net/see.html
Related
I am looking into developing an Java GUI for a biological analysis tool. My question is, Can I use both AWT and SWING libraries under the same Model View Control design pattern? Or,are they two libraries controlled in a distinct way? I would like to know If I can bring them in under the same roof for purposes of reusing existing code written with both libraries. Thank you very much for your time.
Swing is built on top of AWT, you can mix Swing and AWT and it will technically work, but with some limitations:
heavyweight vs lightweight components: components in AWT are heavyweight - they correspond to a native OS window. This means that all AWT components appear above sibling Swing components. (E.g. put a awt List and a swing JList in the same container, and the List will always appear above the JList.)
Look and Feel: the AWT components look and feel native, since they are native components. The Swing components have a pluggable look and feel, which defines their appearance and behavior. If you choose the L&F to match the native platform, these components are only "immitations" of the native look and feel, and can behave differently from their AWT counterparts. (E.g. JButton vs awt Button.)
For these reasons, it might be wise to use just one UI library, presumably Swing.
EDIT: JDK 6 (Update 12) offers seamless integration of heavyweight and lightweight components, so mixing will work seamlessly. So the first point is no longer true - but having inconsistent look and feel between the two UI toolkits still stands.
Hi Yes you can use both. But there is no need, even more it is highly not recommended to mix these two.
For example you can have some serious problems as AWT doesn't have 'depth' concept. No different layers, etc. Other problems are for example, look of components of these frameworks differs.
EDIT:
I am loving this resource. Go ahead and read it there are all issues mentioned, with illustrative examples, which you have to be aware of when you are going to mix these two. http://java.sun.com/products/jfc/tsc/articles/mixing/
Oi,Boro.
I've been writing Java web (JSF, Struts, JSR168) apps for a number of years. With the recent departure of a colleague, it looks like I'm going to be building more client applications. I've used Eclipse since the beginning and I'm really comfortable with it. It feels as though SWT is waning (just an opinion based on literature I can find) and Swing is surging.
My question:
Is there value in learning Swing through writing apps by hand in Eclipse (as opposed to using Matisse in Netbeans)?
Yes, it is very valuable to learn coding Swing apps by hand. One reason for this is that no GUI-Designer I know always does the things you want them to do. The other - and in my opinion more important reason - is that most GUI builders (especially NetBeans') generate all and everything into one single class. This can be very annoying because the maintainability is reduced a lot (separation of concerns). Also many GUI builders have blocked regions, i.e. you cannot modify the generated code by hand. Or if you do the GUI builder will overwrite it the next time you use it.
However that standard LayoutManagers coming with Swing are very complicated. This is why I suggest that you give MigLayout or JGoodies FormLayout a try. On the JGoodies site you also find other libs for alternative Look&Feels, Binding and Validation, which can be very useful.
I would also suggest that you have a look at the Presentation Model pattern (Martin Fowler), which helps a lot if you want to unit-test your GUI-behaviour.
If you then are motivated to improve the design and add some very cool effects to your application check out the book Filthy Rich Clients.
Hope it helps.
Yes, definitely - even if you plan on using Matisse most of the time, you will benefit from having at least a reasonable understanding of the Swing code under the hood.
It sure will help. Maybe you'll reach the end of what Matisse can do, and want to tweak some of the code by hand. At this point it will be better to know what happens under the hood.
Note that using Matisse and writing Swing by hand are not mutually exclusive at all. Matisse just produces Swing code, and you can customize it. You can make part of your GUI with Matisse, and the part next to it by hand, for instance. Get the best of both worlds - that's how I do it, at least.
Fast way to learn how to do something in Swing is to do it in Matisse, and then see the code it produced.
You definitively need to know how Swing works since you will most likely have to adapt and change things which the GUI prgram expects you to know how works and what it is called.
The Java Tutorial has a good Swing trail: http://java.sun.com/docs/books/tutorial/uiswing/
Can I build attractive GUI in Java? If yes, how should I do it? Or should I use some other language or tool to do it?
Filthy Rich Clients is a good book for learning how to use Java to build attractive GUIs that go beyond the usual Swing look.
You can use SWT, which as the other answer mentions is nice for a more native look. You can use JavaFx if you want to add a lot of visual candy, or you can use flash or other technologies and just perform remote operations.
Good luck.
You can just modify Swing look'n'feel as per this Java tutorial.
Attractive is quite subjective, but you can take a look to the Substance LaF (https://substance.dev.java.net/) and the Pushing Pixels blog (http://www.pushing-pixels.org)
If you are looking for a native look and feel in every platform you could use SWT. It's the one used in Eclipse.
You can build very attractive GUI using Java. You can use SWT: The Standard Widget Toolkit.
You have also mentioned if you can use other programming language then you can go for VIsual Basic.It will be easier than compare to Java. As we have to just drag and drop over there.
There are lots of answers on here about using SWT for an attractive native look and feel. However, I would suggest that Swing, set to use the native look and feel, is pixel perfect now, at least on Windows, using java 6. There is no longer a reason to use SWT. I work on a very large Swing project and you would be hard pressed to tell it is not a native windows app.
Edit: Here are a couple of links to some Sun blogs posts that touch on the subject -
http://weblogs.java.net/blog/bino_george/archive/2004/11/hifi_swing_or_i_1.html
http://weblogs.java.net/blog/chet/archive/2006/10/java_on_vista_y.html
Java is just a language. You cannot build a GUI in Java. Period.
The JDK libraries, however, can build guis through various means. You can use AWT, Swing, SWT, JavaFX or GWT libraries to build GUIs--or you can build your own library if you really want.
You can also just create an AWT frame and draw anything you want in it. (I worked on an waveform analyzer (o-scope looking thing) with a GUI written entirely in AWT.
Now, most of those libraries are fairly platform independent, if you want to restrict yourself to a single platform, you can do anything that can be done in C or any other language.
Therefore your question doesn't make too much sense. Are you saying that you want to put in minimum effort and get a good interface? Swing will be less effort than just about any other toolkit out there and can be skinned in more ways than most.
Or are you saying that you want to specify the exact GUI? In that case, don't use swing but there are a bunch of alternatives that should do just what you want.
Can you be more specific (Do you really want help?), or were you just trying to bash Java?
Swing is good in many ways, then why do we need JavaFX?
There is both a technology part of JavaFX that will help design UIs, and a language part that will make writing UIs easier.
The JavaFX technology brings a 2d scenegraph and video capabilities. Afaik these will also be made available generally to java. They are good advancements for creating client side application with fancy and interactive graphical UIs. The 2d scenegraph should make it possible to create more graphic heavy applications that are still responsive.
The JavaFX language is a much better way off creating UIs programatically. Java Swing code can get very verbose, while the same JavaFX code will be smaller and easier to maintain. Closure support makes creating event handlers easier. Declerative assignment of settings makes configuration of elements easier. Native list syntax makes adding components easier.
Please note that I haven't really written any JavaFX, but I have read code and paid attention to what's going on. I recommend trying it yourself to find out what's cooking.
I think Staale's answer is a good start but I would add...
Use JavaFX if
1) If you're interested in developing the application for mobile or TV (note this has yet to be released)
2) If you're working with a graphic designer who is creating the appearance of the application in photoshop and you want to be able to import their look directly.
3) If making the GUI filthy rich is important to you. (so if you want a panel to fade in or out, or slide upon demand)
Use Swing if
1) You're creating an application mainly for the desktop.
2) Performance matters and you know what you are doing (so if you're writing an IDE, Swing would be a better choice)
3) You're looking for a RPC (rich client platform) to build upon.
It is the same reason why we have Java, C++, C#, Python, Perl, Ruby... although we already have C.
Obviously the Java API reference, but what else is there that you all use?
I've been doing web development my entire career. Lately I've been messing around a lot with Groovy and I've decided to do a small application in Griffon just to experiment more with Groovy and also break some ground in desktop development. The only thing is I'm totally green when it comes to desktop apps.
So, world, where's a good place to start?
The Swing Tutorial is very good. Apart from that, the Swing API is obviously the reference, however it's also a treasure trove of fairly good source code! Add the API source to your IDE and you can jump directly to the implementation to all the Swing classes. This is a great way to explore the functionality, see how various Swing components work and learn a good Swing "style". Furthermore, it's great to be able to step through the API classes if things don't seem to work and you have no idea why! Adding the API source to the IDE has the additional benefit that you get all the JavaDocs along with it, although all modern IDEs can also pull them from the net -- you do not want to program desktop Java without the documentation available from within the IDE!
NetBeans and other IDEs do make the creation of IDEs very easy, but be aware that there is a lot more to Swing than just containers and layout managers. In fact, containers and layout managers are among the easier things, and I'd recommend learning to use them by hand, too. There is nothing at all wrong with using a GUI builder, but in some cases it's overkill, and then it's nicer to just quickly whip up a GUI from source. In other cases you need to be able to create a GUI dynamically and then GUI builders are no use at all! For creating very complex layouts from source, I recommend FormLayout, which has its own set of quirks, but which does scale (in terms of programming effort) to very big frames and layouts.
If you've only done Groovy so far, you'll be surprised how well documented Swing and the rest of the Java API is and how well everything is integrated. It might also take some getting used to a different style of programming, using the debugger more often and println-debugging less, etc. There might also be some "boiler-plate" code that will be very annoying. ;) Enjoy.
The Sun Java tutorials are pretty good. I cannot vouch specifically for the Swing one as it has been ages since I've done any Swing development and I have not read it myself.
Creating a GUI with JFC/Swing
When it comes to developing java desktop applications, I would highly recommend using the IDE environment Netbeans. Especially when it comes to the development of Swing based applications.
I recommend you to play around with netbeans. It will allow you to build complete GUIs using only your mouse. Once you get familiar with Swing components, start using the Java API. Thats how I started.
The O'Reilly Swing Book is a pretty good reference, it has a good overview of general Swing concepts and covers each of the major classes. I used it recently when I had to refresh my memory on Swing.