• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

clone JLabel, JComboBox objects

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to clone/copy JLabel & JComboBox objects?
Is this the only way to clone/copy JLabel?


The following test code has these compile errors:
The method clone() from the type Object is not visible
Type mismatch: cannot convert from Object to JLabel
 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will not be able to clone swing components because in general, as they do not implement the Cloneable interface.
Yes, you will need to create the new JLabel by the first way, and if any other properties(like alignment,color) are set to the first object, you need to manually set it in the second one too.
Or alternatively you can write your own class that extends the component you want to do a deep copy & implement the Cloneable interface. In this case you'll have to define how the deep copy is supposed to happen.
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic