Stopping JTabbedPane tab change.

I was wondering if it was possible to stop tab changes on a JTabbedPane.
Right now I am creating an applet with a JTabbedPane and if you click on another tab of the JTabbedPane I am able to capture the event of the change and perform an action using an event stateChanged.
However, I have instances in which I want to pop up a YES_NO_CANCEL JoptionPane instructing whether or not to Save data from that TabPane, and if the user selects cancel, then I want the JTabbedPane NOT to change tabs, I want it to remain on the current Tab with the current data...
Currently I am unable to stop this from Tab change from happening...
I hope someone has an idea of how to easily implement this...
Thanks in advance

Hi,
Thanks for your help..
I solved my problem with a simple solution but I'm not sure whether that one is a right way to do.
I will explain how I implemented. I alreday had my own MyTabbedPane class which extends from JTabbedPane.
I overrided public void setSelectedIndex(int newIndex) method of JTabbedPane, and which I found the changeEvent calls this method first.
So I overrided as below:
    if(oldIndex != newIndex)
      //MyPanel is my customized panel 
      MyPanel prevPanel = (MyPanel)getComponentAt(selectedIndex);
      //promptSaveDialog method returns true after processing save
      //if user choosed Cancel, it returns false
      if(prevPanel.promptSaveDialog())
        super.setSelectedIndex(newIndex);
        selectedIndex = newIndex;
    else
      super.setSelectedIndex(newIndex);
      selectedIndex = newIndex;
    }But it works as of now and I found this as a simple solution. Please let me know if there is some major disadvantages in this design.
Thanks a lot for your support

Similar Messages

  • Stopping Tab Change in JTabbedPane

    When a tab change is requested, I need to do some checking before allowing the change to take place. If the check fails, I need to stop the change from taking place.
    Is this possible with JTabbedPane or do I need to sub-class? TIA
    Paul

    I have moved from Borland Builder C++ and Delphi to Java in the last 4 months so I guess I'm still finding my way here.
    Using the ChangeListener, the tab changing has already taken place when xxxxStateChanged(ChangeEvent evt) is called.
    And to ovveride setSelectedIndex() I would have to subclass JTabbedPane. I was hoping there was an easier way.
    Thanks anyway.
    Paul.

  • How to handle tab change event in UI shell main area

    Hi,
    I have two tabs(two taskflows) in UI shell main area. one is department tab and another is employee tab. My department tab shows employees department wise. On employee tab I have emplyee table which shows employees jobwise. This employee table has the functionality of adding new record to employee vo as well.
    Now i follow these steps.
    1. by defualt department tab is open.
    2. by clickinng on Tasks menu link i open Employee tab in to main area. Now i have both tabs in main area.
    3. at Employee tab I search all employees job = accountant. It shows the search result well.
    4. Now i add a new record to it and without saving/deleting this record i move to department tab.
    5. at Department tab i search employees where department =20, here no relation b/w job and department.
    6. Now i return to employee tab. my newly added record got disappeared. It is there but does not show in table.
    How to resolve it??
    I have one solution in my mind while changing the tab i can prompt to user "you can not leave the newly added record..either save it or delete it". But how to catch tab change event here? where i can write code to prompt msg to user?
    Pls help.
    Edited by: 900997 on May 6, 2012 4:10 AM

    With apologies for the slow reply, I'm currently travelling.
    Two things to note:
    1) The af:document uncommittedDataWarning flag was designed to stop users navigating away from half entered records. More about this flag can be found here:
    http://docs.oracle.com/cd/E23943_01/web.1111/b31973/af_orgpage.htm#CACDDDFH (see point 4)
    http://www.oracle.com/technetwork/developer-tools/adf/unsaveddatawarning-096556.html
    ....please note our documentation from time to time spells this flag wrong with only one "t" in the word committed, so if you're attempting a bulk search check for this (and I'll raise document bugs to get this fixed in the future).
    2) On addressing the ADF UI Shell, if you're switching between "pages" in the UI Shell, as separate to switching between dynamic tabs within a single page using the UI Shell, the UI Shell will actually restart the currently running task flow in the page you're returning too. You can verify this by implementing an initializer on your task flow with a log message, and watching when the initializer is called.
    In addressing your last question, at this stage I think you need to assess my first answer then come back if you think you sill need to execute the code on the tab click. I also need to know are you talking about the primary level of tabs that represent each page in the UI Shell, or are you referring to the dynamic tabs within a single UI Shell page that hold your task flows?
    CM.

  • Long time to open tab "change history" of  business partner in Web_ui.

    Dear experts!
    Long time to open tab "change history" of  business partner in Web_ui.
    4 records were opened for 10-20 seconds
    http://imglink.ru/show-image.php?id=22083a6a576f78c66c86863bf6b0573b
    1. In what may be the reason?
    If the records are many, the discovery may be more than a minute.
    2. Is There a report for the purification of the " Сhange history" over a period?

    Hello Dilip,
    One more alternative would be to increase the time out parameter in ABAP environment.
    The steps to change this parameter:                                                                               
    1) txn: RZ11 -> enter the variable name rdisp/max_wprun_time                      
    2) Display -> Change value -> Then input the value you would like        (ideally 3600)                                                                               
    PS:                                                                          
    1) Don't set this value too big, otherwise general performance will be       
    influenced, since lots of dialogue process will be occupied for a long       
    time                                                                         
    2) This parameter can be changed dynamically                                                                               
    Once the parameter is set please test again. You can try incremental         
    values and test which one does not give timeout error.                                                                               
    please refer to the note 25528 for more details about RZ11.   
    Hope this helps!
    Thanks and Best Regards,
    Shanthala Kudva.

  • How do I stop GoLive from changing the location of my CSScriptLib.js file?

    How do I stop GoLive from changing the location of my CSScriptLib.js file?
    I am making rollovers and want my CSScriptLib.js to be in the same folder as my HTML files.
    Every time I edit the rollovers GoLIve recreates the path of the CSScriptLib.js to file:///Users/xxx/Library/Preferences/Adobe/GoLive/Settings8/JScripts/GlobalScripts/CSScr iptLib.js so it won't work when uploaded. I always need to edit my HTML before uploading. All I want it to say is src="CSScriptLib.js" as the default.

    The site file is a database that keeps track of all your assets (and much more), including the scriptLib file. As soon as the page is saved (when you use the site file and it's open) the link will be change to the correct path that will work on the server.
    If you're not using the site file you might as well use a text editor, since most of GL functionality is gone.

  • How to stop the auto change of the desktop background picture ?

    How to stop the auto change of the desktop background picture ?

    Well . . thanks, but I already have done that and I still have the problem. The background changes to the standard picture galaxy not to one of the options. Sorry my question wasn't clear enough.
    Thanks. 

  • I have my FireFox browser set to delete the history when I close the window. It was working for a while and has recently just stopped with no changes to the settings.

    I have my FireFox browser set to delete all the history when I close the window. It was working for a very long time and has recently stopped with no changes to the settings. This has happened once before and I deleted FireFox and re-downloaded it, that solved the problem for a short period of time but the issue has come up again. How can I fix this?

    Can you check your configuration again? Maybe something went pear-shaped somewhere. It's located in Tools | Options | Privacy and then click the Settings button (see screenshot).

  • Is it possible to have the Firefox Icon in windows' taskbar flashes when any of my app tab changes?

    Is it possible to have the Firefox Icon in windows' taskbar flashes when any of my app tab changes?

    Not possible to configure this in Adobe Reader.

  • At times, the type in the bookmarks toolbar as well as the tabs changes to white with a drop shadow on a white background, making it very difficult to read. I do not know what it causing the colors to change. Is there any way to fix this?

    At times, the type in the bookmarks toolbar as well as the tabs changes to white with a drop shadow on a white background, making it very difficult to read. I do not know what it causing the colors to change. Is there any way to fix this?

    quick test based on screendump from your picture
    1: hue & saturation : master sat -100
    2:levels : input white=67
    OK ?

  • I am trying to set up app tabs, but when I am using one, if I go to a new site from there, the app tab changes to the new site instead of opening in a new tab, then the app tab changes to the new site. Can you help? Thanks

    I am trying to set up app tabs, but when I am using one, if I go to a new site from there, the app tab changes to the new site instead of opening in a new tab, then the app tab changes to the new site. i.e. The app tabs don't stay constant. This occurs while still in Firefox, and does not relate to when I close it. Has anyone got any ideas? Thanks

    If you backed up the iPhone to either iTunes or the iCloud, restore the backup. If not, the data is gone.
    (126342)

  • How do I stop extra tabs from open on start up?

    How do I stop extra tabs from open on start up? When I save new tabs the next time I open I have the new saved tabs. On the next opening after that are the same 7 tabs I don't want and didn't save. edit

    Make sure that the pages aren't set as multiple home page, see
    * [[How to set the home page]] - Firefox supports multiple home pages separated by '|' symbols
    See also:
    * http://kb.mozillazine.org/Preferences_not_saved
    If you use [[Clear Recent History]] to clear the 'Browsing History' when you close Firefox then restoring tabs from the last session ("Save & Quit" or "Show my windows and tabs from last time") doesn't work.
    * http://kb.mozillazine.org/Session_Restore

  • Not option for Transport under the tab Change list in both IR and ID

    Hello All,
    The option transport is missing in tab change list for both IR and ID. We have created the track, maintained the systems in the NWDI but still no luck. We have also included the SC SAP-INTDIR 3.0 for both the tracks (i.e.) IR and ID. Also we are running a seperate NWDI server for CMS and the SLD is with the XI production server.
    Am I missing any configuration? Kindly suggest
    Regards,
    Anand

    Hi Anand
    Please check if the following link is of some good to you:
    http://help.sap.com/saphelp_nw70/helpdata/EN/45/f9f02cf3e41ecce10000000a1553f7/frameset.htm
    Also check for steps mentioned here:
    http://www.saptechies.com/minisap-610-installation/
    I hope it helps
    Regards
    Chen

  • How do I stop AE from changing my workspace when loading a project?

    How do I stop AE from changing my workspace when loading a project?  I've looked everywhere and can't find it.  I work on a lot of projects that a peer works on and his screen size is smaller and his workspace is different than mine.  Is there a setting I can change so that when I open one of his projects my AE window doesn't change?

    No. That behavior is intended. The problem is probably that your colleague uses the "Standard" workspace in a custom configuration and since it is matched by name, it emsses up your "Standard" workspace as well. Therefore advise your colleague to create his own workspace with a custom name and/or create your own custom workspace to be able to more quickly reset things.
    Mylenium

  • Title length in JTabbedPane tabs

    Has anyone ever written code to make JTabbedPane tab titles shorten automatically when there isn't room for all of them in one row?
    Our users like neither of the many-tabs solutions that Swing provides (scroll and multiple rows of tabs), and would prefer a style similar to Eclipse where the tab titles shorten if there isn't room for the entire text.
    All I really want to know is - did anyone do it? And if so a few hints as to how you achieved it.
    Thanks,
    Tim

    Well here is the code I developed in case it is useful to anyone else. Didn't have to do anything clever like work out the length of the text in the end - as you will see in the code:     import java.awt.BorderLayout;
         import java.awt.event.ActionEvent;
         import java.awt.event.ActionListener;
         import java.awt.event.ContainerEvent;
         import java.awt.event.ContainerListener;
         import java.util.Random;
         import javax.swing.JButton;
         import javax.swing.JFrame;
         import javax.swing.JPanel;
         import javax.swing.JTabbedPane;
         import nz.co.timryan.components.CentredButtonPanel;
         import nz.co.timryan.components.FixedWidthButton;
          * Automatically shorten the tab selector titles if necessary to fit them
          * into the width of the space available without scrolling.
          * <br><br>Created on 10/07/2005 by Tim Ryan
         public class BTTTabbedPane extends JTabbedPane implements ContainerListener {
              static BTTTabbedPane instance;
              BTTTabbedPane() {
                   setTabPlacement(JTabbedPane.BOTTOM);
                   setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
                   addContainerListener(this);
                   instance = this;
               * @param args
              public static void main(String[] args) {
                   JFrame frame = new JFrame("TabbedPane test");
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   JPanel main = new JPanel(new BorderLayout());
                   main.add(new BTTTabbedPane(), BorderLayout.CENTER);
                   JPanel buttonPanel = new CentredButtonPanel();
                   JButton addButton = new FixedWidthButton("Add");
                   addButton.addActionListener(new ActionListener() {
                        Random random = new Random();
                        public void actionPerformed(ActionEvent e) {
                             String text = "MARY AND JANE SMITH AND MICHAEL".substring(0, random.nextInt(30) + 1);
                             instance.addTab(text, null, new JPanel(), text);
                   JButton removeButton = new FixedWidthButton("Remove");
                   removeButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             instance.remove(instance.getTabCount() - 1);
                   buttonPanel.add(addButton);
                   buttonPanel.add(removeButton);
                   main.add(buttonPanel, BorderLayout.SOUTH);
                   frame.add(main);
                   frame.setBounds(100, 100, 800, 500);
                   frame.setVisible(true);
              public void componentAdded(ContainerEvent e) {
                   recalculateTitleWidths();
              public void componentRemoved(ContainerEvent e) {
                   recalculateTitleWidths();
               * Shorten the titles of the tabs as necessary to fit the selectors across
               * the width of the available space without scrolling (if possible).
               * Whenever a title is shortened, "..." is appended to the text to show that
               * this has occurred.
               * The full length titles are held in the tooltip text so that the text can
               * be restored if other tabs are deleted, and also so that the user can see
               * the full text by mousing over the title.
              private void recalculateTitleWidths() {
                   int tabCount = getTabCount();
                   int[] tabWidth = new int[tabCount];
                   int availableWidth = getBounds().width - 4;
                   //  Reset the titles to their full text
                   for (int j = 0; j < tabCount; j++) {
                        setTitleAt(j, getToolTipTextAt(j));
                        tabWidth[j] = getBoundsAt(j).width;
                   int totalWidth = getTotalWidth(tabWidth, tabCount);
                   boolean wasShortened = true;
                   // Loop around, shortening titles until all the selectors fit across
                   // the screen, or the titles are too short to be shortened further.
                   while ((totalWidth > availableWidth) && wasShortened) {
                        int longestTab = -1;
                        int longestTabWidth = 0;
                        int longestText = 0;
                        wasShortened = false;
                        // Find the longest tab
                        for (int j = 0; j < tabCount; j++) {
                             if (tabWidth[j] >= longestTabWidth) {
                                  longestTab = j;
                                  longestTabWidth = tabWidth[j];
                                  longestText = getTitleAt(j).length();
                        // Shorten its text (adding "..." if not already done)
                        // and then determine the new tab width and total tab width
                        String title = getTitleAt(longestTab);
                        if (title.length() > 4) {
                             if (title.endsWith("...")) {
                                  title = title.substring(0, title.length() - 4);
                             } else {
                                  title = title.substring(0, title.length() - 2);
                             setTitleAt(longestTab, title + "...");
                             tabWidth[longestTab] = getBoundsAt(longestTab).width;
                             wasShortened = true;
                             totalWidth = getTotalWidth(tabWidth, tabCount);
               * Calculate the total width of the tab selectors.
               * @param  tabWidth the individual widths of the tab selectors
               *         (held in an array for performance reasons)
               * @param  tabCount the count of tabs
               * @return the total width of all tab selectors
              private int getTotalWidth(int[] tabWidth, int tabCount) {
                   int totalWidth = 0;
                   for (int j = 0; j < tabCount; j++) {
                        totalWidth += tabWidth[j];
                   return totalWidth;
    }Regards,
    Tim

  • JTabbedPane: Tab Text, Tab Width and Tab Height

    Whenever i put text on JTabbedPane tab it displays it in one line, so when i have a text e.g. "XXXXXXXXX XXXXXXXXX"
    it displays it as it is not like XXXXXXXXX
    XXXXXXXXX
    How can I display it in two line or more?
    Does Tab width and height automatically adjust itself relative to the text inside it? If not how can I set the tab width and height?
    Thanks in advance.

    leemax quote:
    Simply add the escaped new line character "\n" to display the text of the tab on the next line.
    --Yeah i tried that already but anyway i solved the problem by making used of htnl tags "<br>"                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • Mail crashes when I drag a jpeg from the finder to Mail icon in dock

    I have always been able to drag jpegs to the Mail Icon in the dock to create a new message and send the file as an attachment. recently, I cannot do it, regardless of the attachment size. I drag the attachment to the Mail icon in the dock, a new blan

  • Help, findind a part piece number and seller

    Hi I have a HP LaserJet Enterprise 500 M525f MFP, I have an aditional tray, but a few days we moved from a place to another the whole printer and the "port" where the extra tray connects got broken while trying to plug it back. I don't know whats the

  • Error in linking xla tables with gl

    Hi , We have a requirement in which we have to fetch data from xla tables to post into GL. below is the query i am using to fetch the data, but i am not able to fetch any value from it. Please let me know if i have missed any join condition or there

  • HT3281 64G iPod Touch sync problem with podcasts

    2 of 6 podcasts didn't load when I sync'd my 64G iPod Touch.  They appear to be in the podcast library on my laptop of purchased podcasts. What do I need to do to get them to sync?

  • SocialMiner Reporting using CUIC

    Hi, I have just deployed SocialMiner 9.0 and from the dokwiki, I see that I require CUIC to run the reports. I have read that UCCX 9 comes with CUIC. My question is should I upgrade my UCCX 8.5 to 9 so I can make use of the CUIC to get SocialMiner re