• Post Reply Bookmark Topic Watch Topic
  • New Topic

Prevent tab movement in JTabbedPane  RSS feed

 
Cobin Rox
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings, I have an interesting if not somewhat non-standard problem with JTabbedPane. I have a JTabbedPane with 5 tabs that the user can select. However, on each of the tabs, I'd like for the user to hit the SAVE button (or CANCEL changes button) before s/he is allowed to move to another tab. Therefore, what I'd like to do is intercept the user's movement when s/he attempts to move to a new tab, determine if there are any changes on the current tab, and if so, present a dialog box asking the user if they would like to save changes before moving to the next tab. This will give the user the chance to save the changes and move on to the next tab, cancel the changes and move on to the next tab, or cancel the movement to the next tab and just stay on the current tab.
Just wondered if anyone has had a need/solution for this type of situation.
Thanks
CR
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would just set a FocusListener on each tab and when the focus changes you could pull up a JDialog or JOptionPane requesting the save. Now, I am not good at listeners. But thought the idea might be a good start for you.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!