Performing Custom Painting.

xiaoxiao2021-03-06  55

This Chapter Contains The Following Sections:

How Swing Components Are Displayed describes how painting happens, with special attention to the framework provided by JComponent. Introduction to Painting Concepts gives an overview of the coordinate system, including how borders affect it, and discusses the Graphics and Graphics2D classes. Implementing a Custom Component TELLS How to Implement Painting Code Withnin A Swing Component Using The PaintComponent Method. at The end of this chapter, The summary summarizes this chapter and points to where you can find out more.

How Swing Components Are Displayed When a swing GUI need to paint itself ---- It starts with the highest component that need to be repainted and works his way down the containment hierarchy.This process is managed by AWT painting system, and made more efficient and smooth by the Swing painting manager and double-buffering code. When a component's visible property changes a repaint () method is invoked on the component, if the compoment's size or position also need to change, a call to revalidate () precedes the one to repaint () .The two methods both are thread-safe. (They all excute on the event-dispatching thread). Programs should paint only when the painting system tells them to, because each occurrence of a component painting itself must excute without interruption .For smoothness, Swing components is double-buffered by default - performed to a offscreen buffer and flushed to the screen once finished.For high performance, you should make the component opaque with setOpaque (true) method . When possible The Swing Painting Methods The painting method you're most likely to override is paintComponent It's one of three methods that JComponent objects use to paint themselves The three methods are invoked in this order:.. PaintComponent- The main method for painting. by convention, it first paints the background if the component is opaque. Then it performs any custom painting. paintBorder- Tells the component's border (if any) to paint. Do not invoke or override this method. paintChildren- Tells any components contained by this Component to Paint Themselves. Do Not Invoke or Override this Method.

转载请注明原文地址:https://www.9cbs.com/read-82254.html

New Post(0)