Hello, everybody. Now, I would like to create multiple-step enabled Undo/Redo JButton just like the "Back" "Forward" buttons of IE or Netscape. It looks like a compound-button with a JToggleButton and a dropdown menu. Does any one know how to implement such a button??
Depends on what you are going to need to undo/redo. If its text, you could just store some copys of the complete text based on some *text changed* criterion. Then if they hit undo, you replace what's there(or cache it for redo) with the last copy you have. The number of undo/redos would only be limited to how many copies of the info you could stand to keep. That would work for small text areas. If you were trying to do a text editor that could hold huge amounts of text, you'd have to work up a different system of watching and saving changes. If it's not text I guess you could do something similar where you just have to track your data and store copies based on changes made. As for allowing selection of which particular change they were going back to, You would have to figure out how you were going to display it to the user. Show him the time of the change save(have to save the time with the change)? Show him the beginning of the text changed(hard to implement)? Just show him set value like "Back 1","Back 2"(easiest)? HTH [ February 21, 2003: Message edited by: Chris Shepherd ]
Joined: Jan 08, 2002
Thanks, Chris. Probably I didn't make it clear on what I really need. I do know how to support Undo/Redo based on package javax.swing.undo. What I want to know is, how to draw such a button on screen and make it behaves like a "Back" button of IE. The button should have 2 "sub-button", one is normal, and the other looks like a down-arrow that can bring up a drop-down menu on the screen. And the 2 "sub-button" have some common properties like show border or not at the same time, enabled/disabled together, etc. Does this make sense? .... :roll:
Joined: Jun 27, 2000
ooooh.... well you could put 2 borderless buttons together on a small JPanel and put a border on the JPanel. Don't know right off how you want to display the droplist button, although the back button should be easy. You should be able to do everything together with those buttons on the same panel.