Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Name of JavaBeans

Reply
Thread Tools

Re: Name of JavaBeans

 
 
Kevin Hooke
Guest
Posts: n/a
 
      08-27-2003
When you drag components onto a Container in most IDEs it is generating the
equivalent source code for you. If you look in the source file for the
current Class you are developing you will see the generated source code.

For example, when you drag on a button, you might see some source code like:
JButton btn1 = new JButton("Text on the button");

If the 'name' property on the component you refer to is the name property
inheritted from java.awt.Component, and is it set using setName(String
name), then you can retrieve this name by calling getName() on any
Component.

Hope that helps,

Kevin Hooke
MindBeans Software Consulting
http://www.mindbeans.net

"tommys" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I know that it is not possible to retrieve the name of an object,
> cause there is no such thing as an object name. (only object
> reference) But...
>
> When I drag a button onto a JPanel in JBuilder, I can set the name of
> the component. When I reopen the project later on, the name appears in
> the property editor.It has to be stored somewhere.
>
> So my question is:
> Can I write code to get the property that represents the name that is
> used? Or is this internal information stored in a binary JBuilder
> file? Is there a way to link this to the instance reference? A "dirty"
> way? Any way?
> I had hoped that there was some kind of introspection interface to get
> that name.
>
> Thanks to anyone helping me out on this one.



 
Reply With Quote
 
 
 
 
tommys
Guest
Posts: n/a
 
      08-28-2003
Thanks for your help!

My goal is that components instanciated in JBuilder shall be made
visible to the scripting language Jython. The process will be like
this:

### The user drags i.e a JButton to my custom JPanel:

code generated:
JButton JButton1 = new JButton();
...
...
// There is also a customjpanel that has been added by the user.
this.getContentPane().add(customjpanel, ..constraints..);

customjpanel's overloaded add method:

public void add(Component comp, Object constraints) {

super.add(comp, constraints);
// Interesting part: how to get the string name???
String name = ???
interp.set(name,comp); // interp is the Jython interpreter
}

### After this, a script like this can be executed:

JButton1.setVisible(0) # Jython script

I tried to use the method comp.getName(), but returned null..

My goal is that the user will not have to know about, or edit the
generated code.
So how to get the name of the component. setName is not generated by
JBuilder. I know that JBuilder knows it's name, cause the name is
visible in the property editor of JBuilder.

My workaround is to add a propert called scriptname to all my
components, but had hoped to avoid extending all components adding
this property.

"Kevin Hooke" <(E-Mail Removed)> wrote in message news:<WCa3b.1645$(E-Mail Removed) gy.com>...
> When you drag components onto a Container in most IDEs it is generating the
> equivalent source code for you. If you look in the source file for the
> current Class you are developing you will see the generated source code.
>
> For example, when you drag on a button, you might see some source code like:
> JButton btn1 = new JButton("Text on the button");
>
> If the 'name' property on the component you refer to is the name property
> inheritted from java.awt.Component, and is it set using setName(String
> name), then you can retrieve this name by calling getName() on any
> Component.
>
> Hope that helps,
>
> Kevin Hooke
> MindBeans Software Consulting
> http://www.mindbeans.net
>
> "tommys" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > I know that it is not possible to retrieve the name of an object,
> > cause there is no such thing as an object name. (only object
> > reference) But...
> >
> > When I drag a button onto a JPanel in JBuilder, I can set the name of
> > the component. When I reopen the project later on, the name appears in
> > the property editor.It has to be stored somewhere.
> >
> > So my question is:
> > Can I write code to get the property that represents the name that is
> > used? Or is this internal information stored in a binary JBuilder
> > file? Is there a way to link this to the instance reference? A "dirty"
> > way? Any way?
> > I had hoped that there was some kind of introspection interface to get
> > that name.
> >
> > Thanks to anyone helping me out on this one.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javabeans and JSP's matt Java 2 01-24-2004 09:05 PM
sharing data between javabeans and servlets Gary N Java 1 01-03-2004 08:36 AM
Long term javabeans serialization, compatible with JDK 1.2+ PZ Java 0 12-29-2003 06:10 PM
free swing/awt javabeans? Henrique Seganfredo Java 0 11-30-2003 01:53 PM
Javabeans - handling multiple forms on a single JSP Chris Beach Java 0 09-08-2003 12:00 PM



Advertisments