How to make transparent components.

Source: Internet
Author: User

You should be able to understand it. This is an example of a transparent panel. You can use this method to create other transparent components. Send me a letter if you have any questions. 8 -)
I hope to share my experience with you.
Package com. borland. samples. welcome;
Import java. awt .*;
Public class MyPanel extends Panel {
Private Image bi; // offscreen image
Private Graphics big; // Graphics for the offscreen image
Public void update (Graphics g ){
Paint (g );
}
Public void paint (Graphics g ){
If (bi = null) {// you can't do this from the constructor
Bi = createImage (getSize (). width, getSize (). height );
Big = bi. getGraphics ();
}
Rectangle area = g. getClipBounds (); // this is the area that needs to be (re) painted (no need to repaint everything)
Big. setClip (area );
Big. clearRect (area. x, area. y, area. width, area. height ); // fills the area with the background color // the next statement will call the paint methods for the other panels/components you have added to this panel // and draw them to the offscreen image
Super. paint (big); // now draw the offscreen image to the panel
G. drawImage (bi, area. x, area. y, area. x + area. width, area. y + area. height, area. x, area. y, area. x + area. width, area. y + area. height, this );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.