how to bypass this swing limit

Discussion in 'Java' started by Peter Cheung, Sep 16, 2011.

  1. Peter Cheung

    Peter Cheung Guest

    Dear All
    how to by pass this swing limit:
    Each GUI component can be contained only once. If a component is already in a container and you try to add it to another container, the component will be removed from the first container and then added to the second.

    thanks
    from Peter ()
    Peter Cheung, Sep 16, 2011
    #1
    1. Advertising

  2. On 16/09/2011 18:14, Peter Cheung allegedly wrote:
    > Dear All
    > how to by pass this swing limit:
    > Each GUI component can be contained only once. If a component is already in a container and you try to add it to another container, the component will be removed from the first container and then added to the second.


    Create a new component.

    If you want the components to share state, then you ought to put that
    state in a model object and make the components share the same model.
    State should not be stored in the view anyway.

    --
    DF.
    Determinism trumps correctness.
    Daniele Futtorovic, Sep 16, 2011
    #2
    1. Advertising

  3. Peter Cheung

    Peter Cheung Guest

    share the model can make two components display the same data. Except this, i need to create two set of event to handle mouse click, it is quite trouble.

    thanks
    Peter Cheung, Sep 16, 2011
    #3
  4. On 16/09/2011 18:47, Peter Cheung allegedly wrote:
    > share the model can make two components display the same data. Except
    > this, i need to create two set of event to handle mouse click, it is
    > quite trouble.
    >
    > thanks


    If you have, as you should, written a view/controller class that
    initialises its layout, data and listeners, then the net difference
    between one and two of those is one instantiation and addition to a
    container.

    It sounds like the design of your mouse event handler isn't right.

    --
    DF.
    Determinism trumps correctness.
    Daniele Futtorovic, Sep 16, 2011
    #4
  5. Peter Cheung

    David Lamb Guest

    On 16/09/2011 12:47 PM, Peter Cheung wrote:
    > share the model can make two components display the same data. Except this, i need to create two set of event to handle mouse click, it is quite trouble.


    You originally wanted the same component in two containers. If the
    container handles mouse clicks, and uses them to update the model state,
    why do you need two sets of events? Only one of the two components is
    going to get an incoming event at any one time.
    David Lamb, Sep 16, 2011
    #5
  6. Peter Cheung

    Roedy Green Guest

    On Fri, 16 Sep 2011 09:14:02 -0700 (PDT), Peter Cheung
    <> wrote, quoted or indirectly quoted someone who said
    :

    >Dear All
    > how to by pass this swing limit:
    >Each GUI component can be contained only once.
    > If a component is already in a container and you try to add it to another container,
    >the component will be removed from the first container and then added to the second.


    The obvious answer is clone the component, and make sure you keep them
    up to date with the same state, e.g. by inventing a virtual component
    that you update that in turn updates a list of clones for you.

    Be careful with this kind of logic you don't create endless
    notification loops.

    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    Your top priority should be fixing bugs. If you carry on development,
    you are just creating more places you will have to search for them.
    Roedy Green, Sep 16, 2011
    #6
  7. Peter Cheung

    Peter Cheung Guest

    thanks everybody
    Peter
    Peter Cheung, Sep 19, 2011
    #7
    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. Big Daddy

    Java 1.2 Swing vs. Java 1.5 Swing

    Big Daddy, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    495
    Pete Barrett
    Apr 16, 2005
  2. mkrause
    Replies:
    0
    Views:
    669
    mkrause
    May 6, 2005
  3. lizard
    Replies:
    0
    Views:
    1,761
    lizard
    Jan 30, 2006
  4. Replies:
    1
    Views:
    1,076
    Victor Bazarov
    Jun 28, 2005
  5. S.T
    Replies:
    2
    Views:
    576
Loading...

Share This Page