• java中的重绘


    void java.awt.Container.validate()
    Validates this container and all of its subcomponents.
    这个函数更新容器及其全部子控件,更新容器意味着重新布置它的子控件。布局相关的更改(例如设置子控件的大小位置,向容器添加新控件)会invalidate这个容器。需要注意,当前容器invalidate会自动导致它的父容器进行invalidate(详见Component.invalidate)。因此,要想恢复整个层次的有效性(validity),validate()这个函数应该由最高级别的父容器来调用。容器的validate()是一个费时的操作,故为了性能,程序员最好不要频繁调用它。比如,应该在对容器全部更改完成之后,只调用一次validate(),而不应该是每改动一下都validate一次。如果当前容器不有效,那就会调用它的invalidateTree()函数进行validate它的全部子控件。如果当前容器有效,那就啥都不做。
    Validating a container means laying out its subcomponents. Layout-related changes, such as setting the bounds of a component, or adding a component to the container, invalidate the container automatically. Note that the ancestors of the container may be invalidated also (see Component.invalidate for details.) Therefore, to restore the validity of the hierarchy, the validate() method should be invoked on the top-most invalid container of the hierarchy.

    Validating the container may be a quite time-consuming operation. For performance reasons a developer may postpone the validation of the hierarchy till a set of layout-related operations completes, e.g. after adding all the children to the container.

    If this Container is not valid, this method invokes the validateTree method and marks this Container as valid. Otherwise, no action is performed.

    ==============
    void java.awt.Container.invalidate()

    这个函数使得容器失效,例如:容器的布局为layoutManager2,这个函数会调用layoutManager2.invalidateLayout(Container)。之后,这个函数把这个容器标记为“失效(invalid)”,并且把这个容器的各级父容器都标记为“失效(invalid)”。
    Invalidates the container.

    If the LayoutManager installed on this container is an instance of the LayoutManager2 interface, then the LayoutManager2.invalidateLayout(Container) method is invoked on it supplying this Container as the argument.

    Afterwards this method marks this container invalid, and invalidates its ancestors. See the Component.invalidate method for more details.

    ===========================
    void javax.swing.JComponent.update(Graphics g)

    这个函数调用paint(),它不擦除背景。
    Calls paint. Doesn't clear the background but see ComponentUI.update, which is called by paintComponent.
    ==========================
    void javax.swing.JPanel.updateUI()

    当观感改变之后,调用这个函数进行更新。
    Resets the UI property with a value from the current look and feel.
    =======================
    void java.awt.Component.repaint()

    重绘控件,如果是轻量级控件,这个函数立即调用它的paint()函数。否则,这个函数会立即调用它的update()函数
    Repaints this component.

    If this component is a lightweight component, this method causes a call to this component's paint method as soon as possible. Otherwise, this method causes a call to this component's update method as soon as possible.

    Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.

    ======================

    涉及到重绘的,update()+repaint()足以应付一切情况。update()和invalidate()之后,不会立即引起重绘事件,用repaint()则能够立即重绘。

  • 相关阅读:
    【Gamma】Scrum Meeting 1
    【Gamma】设计与计划
    第五次作业 5.线性回归算法
    第四次作业 4.K均值算法--应用
    第三次作业 3.K均值算法
    第二次作业 2.机器学习相关数学基础
    第一次作业 机器学习概述
    第十五次 语法制导的语义翻译
    第十四次作业 算符优先分析
    第十三次作业 自下而上语法分析
  • 原文地址:https://www.cnblogs.com/weiyinfu/p/5131985.html
Copyright © 2020-2023  润新知