Create cool-style swing interface

Source: Internet
Author: User

In the above several articles, we have modified some of the controls, which have their own brush with some of the simple space, but also the use of pictures to spell, then how we achieve some cool panels it;

Cool Interface

We can see some interface UI effect is very cool, such as rising ah, thousands of listening Ah, and so on, but also to achieve the function of changing skin and so on, figure 1 is the interface of QQ music;

Figure 1:qq Music side

to create your own interface

We use some picture material, Figure 2 is the material picture of Yoyo player;

Figure 2:yoyo Player footage

We can use border to handle the interface, border is mainly used to draw boundaries, the boundary is used to render the entire panel interface, such as code Listing 1:

public class Imageborder implements Border {private Insets Insets = new Insets (0, 0, 0, 0); private image image = NULL; p Ublic Imageborder () {super ();} public void setimage (image image) {this.image = image;} public boolean Isborderopaque () {return is true;} public void Paintborder (Component C, Graphics G, int x, int y, int width, int height) {if (Image!= nul L) {//Generally here we have the window size and picture size set exactly in line with int x0 = x + (width-image.getwidth (NULL))/2; int y0 = y + (height-image.getheight nul L))/2; G.drawimage (image, x0, y0, null); } public Insets Getborderinsets (Component c) {//Margin return Insets;}}

Call the custom border in the panel, such as Code Listing 2:

Image bg = util.getimage ("Player/main.png"); Border.setimage (BG); This.setborder (border); Setpreferredsize (New Dimension (285, 155));

Set up a good picture, match the size, set the boundaries, the above JPanel set to become JFrame Contentpanel

Cannot change size frame.setresizable (false); Suppresses the Border frame.setundecorated (true); Compression size frame.pack ();

Then we can draw our controls on the basis of this picture panel;

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.