This discussion is archived
6 Replies Latest reply: Oct 3, 2006 6:28 AM by JosAH RSS

Problem with calling a constructor.

807598 Newbie
Currently Being Moderated
Hi,

parent is not public in java.awt.Component; cannot be accessed from outside package..

This is my constructor..

public AbstractValidator (JFrame parent, JComponent c, String message){
          this(c, message);
          this.parent = parent;
          popup = new JDialog(parent);
          initComponents();
     }


Here is my call...

objID.setInputVerifier(new NotEmptyValidator(parent, objID, "Field cannot be null."));

Does anyone have any idea what I'm doing wrong?

Thanks in advanced
  • 1. Re: Problem with calling a constructor.
    JosAH Newbie
    Currently Being Moderated
    Have you been peeking at the source code for java.awt.Component?
    There is a parent member variable in that class but it has package scope.
    It isn't even mentioned in the API docs.

    kind regards,

    Jos
  • 2. Re: Problem with calling a constructor.
    807598 Newbie
    Currently Being Moderated
    So, is there anything I can do about this?

    I thought maybe because my textfield I created was private that was why I was getting errors.....

    Thanks Again
  • 3. Re: Problem with calling a constructor.
    JosAH Newbie
    Currently Being Moderated
    So, is there anything I can do about this?
    Well, if you do want to extend from that java.awt.Component class you
    have to play it by the rules: everything that's mentioned in the API docs
    can be used and manipulated but you wanted to touch some of that
    object's internals which is, rightly so, not allowed.

    kind regards,

    Jos
  • 4. Re: Problem with calling a constructor.
    807598 Newbie
    Currently Being Moderated
    I see.. Well thanks for your help.. Learned something new this morning! ;)
  • 5. Re: Problem with calling a constructor.
    807598 Newbie
    Currently Being Moderated
    Ok,

    I found this java swing validation package you can build online. I followed all the steps creating the classes and everything compiles. However, when I make the call to the constructor I still recieve

    "parent is not public in java.awt.Component; cannot be accessed from outside package.." I understand from earlier in this post that I'm trying to access something I'm not aloud to do, but I'm a little lost on how I could go about achieving what I want.

    Many of you might of came across this tutorial...
    http://www.javalobby.org/java/forums/t20551.html

    Do I personally have to create my own package and import it into my program I would like to use it in? If so, how would I achieve this?

    If not any other suggestions??

    Thanks
  • 6. Re: Problem with calling a constructor.
    JosAH Newbie
    Currently Being Moderated
    In your contstructor don't do this:
    this.parent = parent;
    Your Component doesn't know who it's containing parent is. Any
    container will set this value. Look at the Component API docs: there
    is no way to set the parent (using a method).

    You know where the source code is already; have a look at the Container
    addImpl method: it manipulates the parent member variable
    directly. It is allowed to do so because a Container is a Component
    and they both reside in the same package.

    kind regards,

    Jos