Execute instructions before JTabbedPane change of tabulation

Posted on 2006-04-25
Last Modified: 2010-03-31
I use JTabbedPanes,
in one of them the user can do operations that need to be saved (JButton Save).
But if he choose another Tabulation without saving everything is lost.
How can I ask the user to save the operations before the JTabbedPane change of Tabulation ?
Thank you for any help.
Question by:matthew016
    LVL 86

    Accepted Solution

    >>everything is lost.

    Why so?

    You could use a ChangeListener, but at the moment, i don't see why you need to
    LVL 9

    Author Comment

    That's the way my programs works.
    I can't really explain this shortly.
    But in my tabulations I have JPanels but they have not the method addChangeListener.
    LVL 9

    Author Comment

    I see that I can use ComponentListener
    componentHidden(ComponentEvent e)
    componentShown(ComponentEvent e)
    LVL 9

    Author Comment


    Ok I have several problems when I use a ComponentListener:

    1.The event is called after the tab is changed, so I have my JOptionPane above the new tab clicked.

    2.I tought I could ask the user to Save with options Yes, No, Cancel
       And when he clicks cancel the tab shouldn't change, do u think it is possible to do that ?
    LVL 86

    Expert Comment

    It's difficult to assist you only knowing the vaguest details. Suffice it to say at this stage that it's possible to autosave continuously, which i would imagine would cure the problem
    LVL 86

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    canBalance challenge 34 55
    Is there any core JDK API for PDF Creation? 5 31
    wordsWithout 49 64
    array6 challenfge 6 48
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now