Can I apply a Swing look and feel to AWT widgets? - java

I'm developing on a legacy Java desktop application mixing Swing and AWT controls. I can successfully apply the system look and feel to Swing controls of course, but can I do the same for AWT ones? If not, can I implement some bridge in any way?

The basic answer is "no". The AWT components are backed by native OS components, either directly (via OS supplied libraries) or indirectly (via AWT based native components). It's possible that AWT will be linked to "older" component libraries so some of the components won't match the current OS "look and feel", which will be using newer component libraries.
In either case, you can't effect how these components look (and certainly not through Swing's Look and Feel API).
Ok, this might be a little hear say, but The Story Of Awt says "Java's GuiToolkit had to use the native widgets provided by the host window system, whether Windows, Motif, or the Mac. Mimicking the look-and-feel in Java wasn't good enough; it had to be the real native components."

Related

Swing native look and feel vs. AWT style

I've just recently started diving into AWT/Swing as an option to build native UIs and I have made the following observations:
using AWT components on Windows I get a classic look (i.e. Windows 2000)
using Swing components with native look and feel, I get the flatter Windows 10 appearance.
It's the 2nd visual style I'm aiming for, which leaves me with two questions:
Is it possible to somehow make AWT render native components using the newer style?
If not, is Swing's native look and feel actually based on OS native widgets or is it some emulation thereof?
No, it is not supported
It's an emulation, just a Look and Feel like the others

What's the difference between Java Swing & Java Applets

I've got a question today and would like to know which would be better to use in Java development. Which would be better to use: Java Swing OR Java Applet. I am new to Java development and have been confused between the two.
If you were creating a game which would be better to use.
Which is better to understand and uses less lines ect.
Which is light weight?
Any questions would be awesome!
Java Swing OR Java Applet
There is some confusion here.
AWT has Frame for desktop applications/Applet for applets.
Swing has JFrame for desktop applications/JApplet for applets.
Other matters:
AWT/Swing. Why AWT rather than Swing? See this answer on Swing extras over AWT for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see Mixing Heavyweight and Lightweight Components.
Applet vs. application. Why code an applet? If it is due to spec. by teacher, please refer them to Why CS teachers should stop teaching Java applets.
Many of the components in javax.swing.* have made other still accessible JDK components obsolete, such as AWT. Swing is actually built on top of AWT, and is a large improvement in performance, features, and usage over AWT.
This tutorial on custom graphics with Swing may help:
http://www.ntu.edu.sg/home/ehchua/programming/java/J4b_CustomGraphics.html
As for Java Applets, these are unrelated to Swing in terms of normal application development. Java Applets are small applications that can run in a web browser.
Swing is a set of platform independent UI tools (JButton, JScrollBar, etc.). It guarantees that your user interface design will look the same on different platforms. An applet is an app that runs inside a browser or other hosted environment. An applet can use Swing UI, but doesn't need to.
Personally, I wouldn't develop a game in either if it's graphics intensive. If you want lightweight, I would suggest using JavaScript in Chrome's V8. Check out Chrome's developer showcase. They're doing amazing things with Javascript these days.

SWT and AWT, what is the difference?

I understand that this question is rather general and kind of a holy war. Could you explain to me why SWT is successful when AWT is not, while these two frameworks use the same idea of native ui controls. What makes SWT different comparing to AWT? Just few words if possible.
Thank you.
AWT is the original cross-platform, native-peer based GUI widget set. It drew a lot of complaints for not being perfectly consistent across platforms. Sun built the Swing widget set to answer those concerns, building it with pure Java (no native peers), but people complained that it was slow and ugly.
IBM built SWT as a native-peer based competitor to Swing. It succeeded because it looks good, performs well and is pretty consistent across platforms. It cemented it's position by getting used by many popular applications, Eclipse and Vuze being the most obvious.
SWT provides a lot richer set of native heavyweight widgets than AWT - a proper comparison would be SWT vs AWT/Swing. Due to that, SWT looks more native than AWT/Swing. While this could be considered a success, it can also be a drawback, depending on what you need to implement. In case of SWT you are using only heavyweight native widgets with all possible OS limitations. With AWT/Swing you have the option to mix lightweight Swing (pure Java) widgets with native AWT widgets for better performance.

AWT XOR SWING together in one application?

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.

If Swing has more features to design a form. Then what is the use of AWT in java?

In java, Swing has more features than the AWT components.
For example,
In AWT,
TextArea ta;
Button btn;
But its same in Swing as,
JTextArea ta;
JButton btn;
But swing component has good in look.
Then what's the need of AWT. Is there any useful feature?
Swing and AWT both provide user interface components, however Swing is built on top of AWT. It provides richer tools like icons, tool tips, etc. which are not available in AWT. Also, Swing is meant to be portable, while AWT (in theory) will match more of the system's look and feel.
Most IDEs that give you GUI building features (NetBeans, etc) will do so using Swing components. AWT is useful since it provides the foundation on which Swing is built.
More details here.
AWT is useful if you want truer O/S fidelity and can accept a lowest-common-denominator for widget support.
It's also immensely useful for building your own light-weight GUI on (suppose, for a game engine). For example, we needed a GUI system which would run on handhelds in JME PP 1.0 as well as desktops and thin clients, where we needed only a few basic components, but really minimal overhead, so I built a GUI toolkit which runs within an AWT Panel. It worked out really well.
AWT was the GUI package available in Java, then along came Swing, which was built on top of AWT in an attempt to make things look nicer and consistent across platforms. The problem is, they both look terrible. I am stuck with AWT in my project unfortunately, because it is a Windows Mobile project and our VM only supports AWT.
If you want a java GUI that actually looks nice (well nicer than Swing or AWT) then you want to check out SWT from IBM.
AWT was the first try on UI for Java, later Swing provided a better alternative because they use "light" components ( the component draw the UI them selves instead of relaying on native code ) and those light components were way lot flexible and maintainable then AWT.
AWT still has it's place as the underlying "technology" that interface Swing and the OS ( JComponent inherits java.awt.Container after all) , so, its place in the low level of UI. For instance, things like translucency, shapes etc. are placed in AWT package and they are used by Swing components.
New platform UI features will be added to Java in the following releases and many of them will be added to the java.awt. package.
AWT is still commonly used for applets! Most web browsers support AWT classes, so AWT applets can run without the Java plugin. Swing applets, however, require the Java plugin. Swing is not supported by older JVMs.
AWT is slighter faster because it uses native OS peer components, whereas Swing draws all its own components at the bit level. Swing components may not look and behave exactly like their native counterparts. AWT applications, however, will look like native apps and so will look different on different platforms. In contrast, Swing apps will look the same on all platforms (although this can be changed with code).

Categories

Resources