Java GUI customizing JPanel Sketchpad background

Customize JPanel panel background

1、 Foreword

1. The full name of GUI is graphical user interface, that is, graphical user interface. Java GUI is widely used, and it is also very common in our life. Many applications use the GUI programming design, such as clicking the QQ icon to pop up the corresponding login window.

Generally, the interaction between programs and users is based on the running interface of the corresponding program.

2. JPanel panel is a panel container class under swing. The panel supports nesting. You can set the layout mode, set different layout managers, and add other controls, such as JButton button, jtextfield text box, etc. To design and improve a program interface form.

As a drawing panel, the method of supporting setbackground () to set the background color is far from enough. Here, you can customize the image background for JPanel.

2、 Platform tools

1.MyEclipse

Here is a demonstration of using MyEclipse 2014

Other platforms that support Java AWT + swing are also available

3、 Graphic display

1. Effect of different processing JPanel under the same window

(1) First, create an unmodified form. The general default JPanel interface effect is as follows:

(2) Simply set the background color effect:

(3) Customize the form effect under JPanel after processing:

2. Code implementation

Custom JPanel background processing, the picture is BG PNG is in the same path as the test class. Use pictures. Pay attention to the relative path

4、 Expand layout manager

Here is a simple login form:

Based on the custom JPanel background, set the gridbaglayout layout and add basic controls such as button text box to realize a simple login form.

(1) The code is as follows:

Where ddmbg is the picture name

(2) The implementation effect is shown in the figure:

Layout is the basic and very important knowledge in GUI design.

Proficient in using and mastering the three layouts and other layout managers, you need to practice typing code yourself.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>