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.
精彩评论