Java:jpanel control cannot display the problem

Source: Internet
Author: User

http://blog.csdn.net/gcangle/article/details/8222005

————————————————————————————————————————————————————————

In doing an embedded camera project, encountered such a depressed problem.

A new class inherits JPanel, adds some controls to it, joins it in the original JFrame, and then jpanel the controls in anyway.

(For ease of control the ContentPane layout is "BorderLayout", while the JPanel layout is "absolute", JPanel is placed in the North position of Contenpane)


Then the internet to check a lot of information, but still can't solve. can only explore themselves.

After a day of trying, a strange phenomenon was discovered.

When you inherit the layout of the class

Getcontentpane (). Add (comp, borderlayout.center);

The time. The control of this class can actually be displayed properly. While others such as Getcontentpane (). Add (comp, Borderlayout.north), the control cannot be displayed.

It's a magical existence!

So further exploration finally found the core of the problem! Sum up on a sentence

When you write the JPanel layout is null, can only be placed in the center position, otherwise it will not be displayed!

Or, as long as you change the layout to non-null, everything is fine.

——————————————————————————————————————————————————————————————

You should also pay attention to this situation in topcomponent ...

Java:jpanel control cannot display the problem

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.