🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #15047

Re: When getParent() is available ?

#15047
From: Matt Welsh
Date: Tue, 13 Jul 1999 00:00
71 lines
2188 bytes
Without seeing your code I'm pretty sure that what's going on is that 
you haven't added it to a container so it has no parent.
The following bit of code demonstrates this:

package untitled13;

import java.io.*;
import java.util.*;
import java.awt.*;

public class Bug1 extends Frame{
  public Bug1() {
      MyPanel p = new MyPanel();
      p.printParent();
      add(p);
      p.printParent();
  }

   public static void main(String args[]) {
      Bug1 bug = new Bug1();
   }
}

class MyPanel extends Panel {
  public MyPanel() {
    System.out.println(this.getParent());
  }

  public void printParent() {
    System.out.println(this.getParent());
  }
}

The output is :

[c:\jbuilder3\myclasses]java untitled13.Bug1
null
null
untitled13.Bug1[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,resizable,title=]

Until the add statement in the Frame is reached, the panel is
unparented.


-Matt

Christophe wrote:
> 
> Hi
> 
> I've done a component derived from Panel. I need to know if I'm executing in
> an applet or in a stand alone application. To do that I use the getParent
> function and test if I can assigned it to a java.applet.Applet and this
> until getParent() is null. It's running well.
> But if i use it in the constructor, it failed, the parent seems to be not
> available.
> Where must I put this code? I've tried to override the validate method but
> it failed so.
> 
> Thanks in advance.

-- 
/**
 * Matt Welsh
 * Borland
 * R&D Engineer, JBuilder
 *
 * @param email mwelsh@Borland.com
 * @param WWW http://www.borland.com
 * @deprecated http://www.inprise.com
 */
Technical Details
Message-ID: <378BB900.FEAA4205@inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7mfs4t$g521@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,4151ac4308879afd
X-Google-Attributes: gidf74b3,public
From: Matt Welsh <mwelsh@inprise.com>
Subject: Re: When getParent() is available ?
Date: 1999/07/13
Message-ID: <378BB900.FEAA4205@inprise.com>
X-Deja-AN: 500687890
Content-Transfer-Encoding: 7bit
References: <7mfs4t$g521@forums.borland.com>
Organization: Inprise Corporation
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language