• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why I cannot undo this??

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Friends:
I have a project that has following requirements,

When I click the "Group" button, I can add a JPanel to the current component,when I keep clicking the "Group" button, I can add a series of JPanels to the current component layer by layer, for example, after I click "group" button 5 time, "Label 1" has 5 layers of JPanels totally, It looks good to me,
but I need to undo what I did before, so When I click "ungroup" button, I hope to take off each JPanel by each clicking, If I keep clicking "ungroup" button 5 times, I hope to have only ONE "Label 1" dispaly in the Main Panel.

So far My situation is that I can only take off last layer of JPanel, and I cannot go ahead to the inner most part, ie "Label 1".

I know it is a Do-and-Undo problem, but I am not sure I am on the right track or not, please advice how to solve this??
Thanks

 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The containment hierarchy has all the information we need for this. You can use methods in
the Container class api to traverse this hierarchy, locate components and add/remove as
desired. The SwingUtilities class api has handy methods for converting Points and Rectangles
between the coordinate systems of different components.
Here's an example of one way to do this. When the "Group" radiobutton is selected clicking
on any label with the mouse will add a new, outer parent to the label. Likewise, when the
"Ungroup" radiobutton is selected the outer-most parent is removed with each mouse click on
a label. Dragging of labels will work when the "No Action" radiobutton is selected.
 
Michelle Wang
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much, very good code.
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic