Article View: borland.public.jbuilder.java.swing
Article #9429Re: Leaving a JTabbedPane
From: Paul Furbacher [TeamB]
Date: Wed, 15 Mar 2000 00:00
Date: Wed, 15 Mar 2000 00:00
30 lines
2133 bytes
2133 bytes
Jeff Marendo wrote: > I have a JTabbedPane with several tabs on it. Each tab has a panel with > components that a user will be using to enter and view data. On one of my > tabs, a user can initiate a process to create a new "widget". I want to > make it so that if a user initiates that process, but decides to switch to > another tab before hitting a "confirm" button, a JDialogBox will be > displayed to the user (before showing the tab they're trying to click on) > informing them that they didn't confirm their change and that if they leave, > they'll lose all of their changes. > > I plan on using a "dirty" flag to track whether or not they tried to > initiate the new widget process. However, I don't know how to go about > tracking when they try to leave this tab and firing off the JDialogBox > BEFORE showing the other tab they're trying to switch to (I don't care if > they're just switching between different windows applications). Can anyone > give me any pointers or suggestions how to go about this? Add a "stateChanged" listener to the tabbed pane. In the event handler, check the dirty flag. If "dirty", pop up the dialog box. If the user says to save, force the tabbed pane selected index to the one which the user just left. I just tried this general scheme (minus the dialog box) by setting the selected index to 0 no matter what I select. It never leaves the first tab. Based on that simple test, you should be able to do what you want with this approach. Paul Furbacher (TeamB)
Technical Details
Message-ID:
<38D018DE.489AEA47@home.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8ajqhi$p9v6@bornews.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,43d6d60a05065d15 X-Google-Attributes: gid111d45,public From: "Paul Furbacher [TeamB]" <pnf@home.com> Subject: Re: Leaving a JTabbedPane Date: 2000/03/15 Message-ID: <38D018DE.489AEA47@home.com> X-Deja-AN: 598026468 Content-Transfer-Encoding: 7bit References: <8ajqhi$p9v6@bornews.borland.com> X-Accept-Language: en,pdf Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Reply-To: pnf@home.com Newsgroups: borland.public.jbuilder.java.swing