Results 1 to 6 of 6
  1. #1
    jroch is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Question Sub-Sub-Class masking Sub-Class' controls

    UPDATE: Problem Solved. Close thread.

    Sorry for the confusion. The problem was ChildPanel was painting over ParentPanel's controls. I was asking how to stop ChildPanel from painting over ParentPanel's controls.

    The solution is simply to comment out ChildPanel.constructor's call to initComponents(); This prevents the layout manager from positioning ChildPanel's panel overtop of ParentPanel's controls.






    ==============================

    I have a ParentPanel class with a bunch of controls. ParentPanel is subclassed to ChildPanel. ChildPanel has no controls but I want to add more code.


    public class AppFrame extends javax.swing.JFrame
    {
    ChildPanel childPanel;

    public AppFrame()
    {
    initComponents();
    setTitle("Sub sub class");
    setSize(400, 300);
    childPanel = new ChildPanel();
    // using border layout
    add(childPanel, BorderLayout.CENTER);
    }

    // omitted generated code on the layout manager
    }


    public class ParentPanel extends javax.swing.JPanel
    {
    public ParentPanel()
    {
    initComponents();
    }

    // omitted generated code and variables for controls
    }


    public class ChildPanel extends ParentPanel
    {
    public ChildPanel()
    {
    initComponents();
    }

    // omitted generated code
    }


    When the app opens the ParentPanel controls are either covered by ChildPanel or not drawn at all. What can I do to keep ParentPanel's controls visible and functioning and add more code to ChildPanel? Am I even using the correct GUI classes?

    thanks.
    Last edited by jroch; 02-17-2012 at 08:05 PM. Reason: problem solved

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Sub-Sub-Class masking Sub-Class' controls

    It's hard for me to say what's wrong based on the information as presented. I'm guessing that you have layout issues, but again with the scant information posted so far, this is just a wild guess. If you are new to Swing, I strongly urge you not to use a code generator to create your applications but instead to go to the Swing tutorials and learn to create applications by hand. Then you'll know exactly what your code is doing or if not doing, where the problems are located, and you'll know what code to show here to make your questions answerable.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Sub-Sub-Class masking Sub-Class' controls

    Does also look like gross misuse of inheritance. Subclassing most emphatically does not represent a parent-child relationship.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    jroch is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Sub-Sub-Class masking Sub-Class' controls

    Quote Originally Posted by DarrylBurke View Post
    Does also look like gross misuse of inheritance. Subclassing most emphatically does not represent a parent-child relationship.

    db
    Inheritance (object-oriented programming) - Wikipedia, the free encyclopedia

    In classical inheritance where objects are defined by classes, classes can inherit attributes and behavior ... from pre-existing classes called base classes or superclasses or parent classes or ancestor classes. The new classes are known as derived classes or subclasses or child classes.

    So based on Wiki's definition (relative to my app):
    ParentPanel = base class aka superclass. Provides a bunch of controls and some generalized functionality.
    ChildPanel = subclass aka child class
    and JPanel would be the superclass of ParentPanel.

    ...

    A subclass, or child class, is a modular, derivative class that inherits one or more properties from another class (called the superclass, base class, or parent class). The superclass establishes a common interface and foundational functionality, which specialized subclasses can inherit, modify, and supplement.

    In my case ChildPanel is inheriting ParentPanel's controls and functionality and then modifying and supplementing some of that functionality.

    Thank you for taking the time to read my original post.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Sub-Sub-Class masking Sub-Class' controls

    So rather than post some code and a clarification of your problem, you've chosen to debate the merits of inheritance. I'm going to assume then that you've solved your problem, because if you haven't I'd have thought that you would have done the former rather than the latter. If my assumption is wrong and you still need our help, consider giving us more information. The link below and here on How to Ask Smart Questions can give good tips that can help let you know just what information we need.

  6. #6
    jroch is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Sub-Sub-Class masking Sub-Class' controls

    Quote Originally Posted by Fubarable View Post
    So rather than post some code and a clarification of your problem, you've chosen to debate the merits of inheritance. I'm going to assume then that you've solved your problem, because if you haven't I'd have thought that you would have done the former rather than the latter.
    The tone of your response is not appreciated Moderator Fubarable. Let's move onto other things.

    There is no need to make any assumptions about the state of the problem. Please see the "Last edited" time stamp of the first post 8.05pm at which time I declared the problem solved. Moderator DarrylBurke came along 24 minutes later at 8.29pm and publicly made what I interpreted as a veiled shot. At 9.09pm I made a rebuttal that was fair and without drama.

    Please research the facts before accusing me of purposely going off topic and "chos[ing] to debate the merits of inheritance" instead of producing more clarification.

    ... and would somebody please close/lock this thread before postings get personal.

    Have a nice day.

Similar Threads

  1. Replies: 3
    Last Post: 01-27-2012, 12:20 AM
  2. Replies: 0
    Last Post: 12-07-2011, 12:55 PM
  3. Replies: 0
    Last Post: 03-27-2011, 06:49 AM
  4. Replies: 5
    Last Post: 01-26-2011, 07:38 PM
  5. Replies: 8
    Last Post: 03-21-2009, 10:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •