Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: JPanel-type class doesn't apear on the JFrame?

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JPanel-type class doesn't apear on the JFrame?

    I created a class named Surface the inherites from JPanel. This class draws a General Path inside it's paintComponent(). I tried adding it to a JFrame and it doesn't get displayed.

    Then I was advised to give the Surface instance a preferredSize, and it now displays correctly.

    My question is: Is the default for JPanel-type objects that only have a GeneralPath in their paintComponent() (no rectangles and other shapes), to be invisible until you explicitly set their preferred size?

    Thanks


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: JPanel-type class doesn't apear on the JFrame?

    No.

    Please show the code that wasn't working correctly so that we can determine the reason.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: JPanel-type class doesn't apear on the JFrame?

    Quote Originally Posted by AvivC View Post
    My question is: Is the default for JPanel-type objects that only have a GeneralPath in their paintComponent() (no rectangles and other shapes), to be invisible until you explicitly set their preferred size?
    Not exactly. The size (and location) of a component depends on the container in which you add the component:
    a) if the container uses a layout manager or not.
    and
    b) if there is a layout manager, in which area (depending on the specific layout manager).

    For example, if a container has a BorderLayout and you put a component in the CENTER area, then any set of the preferred size is totally ignored.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JPanel-type class doesn't apear on the JFrame?

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/84460-jpanel-type-class-doesnt-apear-jframe.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. My JPanel-form doesn´t show up
    By iHank in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 11th, 2013, 12:03 PM
  2. Calling a JPanel into another Jpanel in a JFrame
    By aknessy in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 17th, 2013, 10:14 AM
  3. Adding a Jpanel from another class to JPanel in a main class
    By saniadeyi in forum What's Wrong With My Code?
    Replies: 0
    Last Post: July 22nd, 2013, 03:20 AM
  4. Replies: 5
    Last Post: February 15th, 2013, 05:01 PM
  5. JPanel in JFrame
    By maele in forum AWT / Java Swing
    Replies: 2
    Last Post: March 8th, 2010, 04:12 AM

Tags for this Thread