Results 1 to 5 of 5
  1. #1
    ellias2007 is offline Member
    Join Date
    Feb 2010
    Posts
    25
    Rep Power
    0

    Default SAME JComboBox in 2 JPanles?

    Hi every body
    i need to add the SAME JcomboBox to 2 Jpanels...
    In fact, when i do :

    Java Code:
    Panel1.add(Cmb);
    Panel2.add(Cmb);
    when i add the Cmb to Panel2 : it disappears from Panel1

    How to add it to the 2 JPanels at the same time
    Thanks for any help
    :confused:

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,446
    Rep Power
    25

    Default

    A component has a parent pointer, that would be set to the last container it was added to.

  3. #3
    ellias2007 is offline Member
    Join Date
    Feb 2010
    Posts
    25
    Rep Power
    0

    Default

    Thanks Norm for your quick reply... :o

    Can you be more clear with more details please ?

    What the code must be ?

    Many thanks

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,446
    Rep Power
    25

    Default

    How can a component be in two containers if it has a reference to its parent.
    There is only ONE reference, hence it can only be in one container.
    The solution is to redesign your program.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default

    Norm is right: a component can only be a child in one single parent container but note that all Swing components use a strict separation of the model and view, i.e. you can very well install to JComboBoxes with one single ComboBoxModel.

    kind regards,

    Jos

Similar Threads

  1. Replies: 2
    Last Post: 12-10-2009, 01:58 PM
  2. I need help with JComboBox
    By eva21 in forum New To Java
    Replies: 1
    Last Post: 11-28-2008, 10:05 PM
  3. JCombobox
    By daniel50096230 in forum NetBeans
    Replies: 1
    Last Post: 09-21-2008, 12:23 PM
  4. JComboBox
    By Fosters in forum AWT / Swing
    Replies: 0
    Last Post: 08-10-2008, 01:22 PM
  5. jcombobox
    By Freddie in forum AWT / Swing
    Replies: 4
    Last Post: 05-11-2007, 12:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •