Re: Name of JavaBeans

Discussion in 'Java' started by Kevin Hooke, Aug 27, 2003.

  1. Kevin Hooke

    Kevin Hooke Guest

    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" <> wrote in message
    news:...
    > 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.
    Kevin Hooke, Aug 27, 2003
    #1
    1. Advertising

  2. Kevin Hooke

    tommys Guest

    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" <> wrote in message news:<WCa3b.1645$>...
    > 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" <> wrote in message
    > news:...
    > > 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.
    tommys, Aug 28, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Beach
    Replies:
    0
    Views:
    581
    Chris Beach
    Sep 8, 2003
  2. Henrique Seganfredo

    free swing/awt javabeans?

    Henrique Seganfredo, Nov 30, 2003, in forum: Java
    Replies:
    0
    Views:
    348
    Henrique Seganfredo
    Nov 30, 2003
  3. PZ
    Replies:
    0
    Views:
    353
  4. Gary N
    Replies:
    1
    Views:
    726
    Herman Timmermans
    Jan 3, 2004
  5. matt

    Javabeans and JSP's

    matt, Jan 24, 2004, in forum: Java
    Replies:
    2
    Views:
    348
Loading...

Share This Page