This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Any ideas on lightweight component support (probably important for swing)?
- From: Brian Jones <cbj at gnu dot org>
- To: "Scott Gilbertson" <scottg at mantatest dot com>
- Cc: <java at gcc dot gnu dot org>
- Date: 21 Apr 2003 18:14:14 -0400
- Subject: Re: Any ideas on lightweight component support (probably important for swing)?
- References: <00ae01c3081e$b5215ed0$3c16a8c0@mantatest.com>
"Scott Gilbertson" <scottg at mantatest dot com> writes:
> I submitted a small patch a while ago entitled: "Patch:
> GLightweightPeer,LightweightPeer,Toolkit allow creation and display of
> lightweight components"
> (http://gcc.gnu.org/ml/java-patches/2002-q4/msg00344.html). The problem I
> was trying to solve is that you couldn't create a lightweight component,
> because java.awt.Toolkit.createComponent returned null so you'd get a
> NullPointerException. I think this problem will need resolution in order to
> implement swing, which uses lightweight components. I also needed it for my
> awt application, which uses tons of custom lightweights (as do many awt
> applications). The patch hasn't gone in yet, due to concerns about whether
> I took the right approach.
>
> I'm wondering if anyone knows a better approach than the one I took.
>
> I therefore figured we needed to make LightweightPeer an extension
> of ContainerPeer (rather than ComponentPeer) and return a
> LightweightPeer from createComponent.
I think this is wrong. A LightweightPeer is not necessarily a
container, though you may implement a container based upon one.
> createComponent javadoc from jdk 1.4.0:
> -------------------------------------------
> protected java.awt.peer.LightweightPeer createComponent(Component target)
> Creates a peer for a component or container. This peer is windowless and
> allows the Component and Container classes to be extended directly to create
> windowless components that are defined entirely in java.
>
protected Component()
Constructs a new component. Class Component can be extended directly
to create a lightweight component that does not utilize an opaque
native window. A lightweight component must be hosted by a native
container somewhere higher up in the component tree (for example, by a
Frame object).
All JComponents extend Container.
> It may seem strange to implement both the ContainerPeer and ComponentPeer
> interfaces in GLightweightPeer, but I think it's necessary in order to meet
> the "Creates a peer for a component or container" requirement from the 1.4.0
> javadoc.
>
> Does anyone see a flaw in this logic, or perhaps know of a cleaner way to
> get LightweightPeer working?
I'm of the opinion Container is implemented on top of LightweightPeer
rather than inside of it. I do not know for sure what it means for a
window-less component to extend Component... what affect it has on
'show' and 'hide', etc... but I'll probably find out sometime this
year.
Brian
--
Brian Jones <cbj at gnu dot org>