Java GUI Swing Model Explanation

主宰稳场 提交于 2020-01-22 05:26:17

问题


I've been working with Swing for a while now but the whole model/structure of JFrames, paint(), super, etc is all murky in my mind. I need a clear explanation or link that will explain how the whole GUI system is organized.


回答1:


The same happened to me. Actually to this day I don't quite get 100% how all it works.

Swing is a very flexible framework - perhaps too flexible. With flexibility comes a lot of abstraction and with abstraction comes confusion. :)

I've found the following articles worth reading. They helped me to better understand the big picture of Swing.

  • A Swing Architecture Overview
  • The process of installing a UI delegate, which is just this image:

They explain quite well how the model and the delegate work. It always drives me mad when I see those JLabel, LabelUI, ui.update, etc.




回答2:


Have you looked at the Java Swing Tutorial (click here)? It does a pretty good job of covering the basics of developing Swing applications.




回答3:


Since this question is tagged with JFrame, I'll suggest a few links for understanding how JFrames and other top-level Swing containers work.

I also found that Swing was (and still is) quite involved and taking a look at the documentation provided by Sun is required every once in a while -- Every time I check, I seem to learn something new.

First, the basics: JFrame class from the Java API Specifications. The Java API Specifications often provide good detailed information about the classes. In this instance, you'll notice that there are several links such as How to Make Frames section from The Java Tutorials.

Aside from that, I'll also recommend looking at the Lesson: Using Swing Components from The Java Tutorials. The lesson provides instructions on how to use the components provided in Swing along with some useful examples.

For more specifics parts that I've found confusing when I started with Swing was all the different types of panes, such as the ContentPane, RootPane, GlassPane. The Using Top-Level Containers section provides information and helpful diagrams on the container hierarchy of the top-level containers. The How to Use Root Panes section gets into the details about the Glass, Layered, and Content Panes with plenty of examples.




回答4:


I found Swing Explorer to be a precious tool to understand the hierarchy of components (particularly in complex GUIs) and look at properties (alas, read-only: we get used to Firebug convenience!). It has an Eclipse plugin.




回答5:


Filthy Rich Clients by Chet Haase and Romain Guy is a great book about Java UI. It covers some more advanced stuff too, but introduction and few first chapters explain fundamental things well.




回答6:


If, after reading the Swing tutorial, you find your interest lies in more advanced topics, you may also wish to look at Swing Second Edition by Robinson and Vorobiev.




回答7:


I've found that simply browsing around in the source code (ctrl-click on a name if you're using NetBeans) has been really helpful. If I see a method appear in the completion dialog that I'm not familiar with, I'll just click "Go to source" and look around until I'm comfortable with it.



来源:https://stackoverflow.com/questions/370259/java-gui-swing-model-explanation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!