How to Stop Repaint in Java With JPanel

How to Stop Repaint in Java With JPanel thumbnail
Normally, a program written with Java's built-in GUI packages automatically repaint themselves when conditions change.

Java's built-in Swing and AWT libraries enhance the process of creating and displaying elements of a graphical user interface. A JPanel is a Swing component that holds the contents of a GUI, such as buttons and text boxes. By default, Swing records the state of GUI objects and automatically repaints them on the screen whenever a user's actions change them. However, you can choose to disable automatic repainting and replace its function with your own code.

Instructions

    • 1

      Grab the reference to your JPanel, e.g. "JPanel myPanel."

    • 2

      Access the repaint manager for your JPanel, e.g:

      RepaintManager myPanelsManager = RepaintManager.currentManager(myPanel)

    • 3

      Tell the repaint manager not to repaint your JPanel when it changes, e.g.:

      myPanelsManager.markCompletelyClean(myPanel);

Tips & Warnings

  • You can also use the line, "myPanel.setIgnoreRepaint(true)" to prevent the operating system from repainting your JPanel. System calls will not be affected.

Related Searches:

References

  • Photo Credit Digital Vision./Digital Vision/Getty Images

Comments

Related Ads

Featured