Making the ChangeListener only fire once on a JTabbedPane

Hi guys, I'm having a problem with the amount of times that a ChangeListener for a JTabbedPane is called. If the user clicks on a certain tab, a JOptionPane is displayed with a message. However, I can't figure out a easy work around to make it so the listener only executes the code within it only once - I don't want the JOptionPane to come up twice. I tried doing a not-so-great boolean method:
private void setPass(){
     if (pass)
          pass = false;
     else
          pass = true;
}and calling it from within the listener, but I'm having trouble with it. Anyone know how to make it so the lister only fires once, or at least only displays the dialog once? I tried searching the forums using keywords such as "JTabbedPane ChangeListener pass once twice... etc" but it didn't bring anything relevant up. Thanks!

are you sure you're using a changeListener?
works OK in this
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
class Testing
  public void buildGUI()
    final JTabbedPane tp = new JTabbedPane();
    for(int x = 0; x < 5; x++) tp.addTab(""+(char)(x+65),new JPanel());
    JFrame f = new JFrame();
    f.getContentPane().add(tp);
    f.setSize(300,200);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    tp.addChangeListener(new ChangeListener(){
      public void stateChanged(ChangeEvent ce){
        JOptionPane.showMessageDialog(null,tp.getTitleAt(tp.getSelectedIndex()));
  public static void main(String[] args)
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        new Testing().buildGUI();
}post a sample program so we can see what you're doing
(by compiling/running the sample program)

Similar Messages

  • Terminatio​nStateChan​ged Callback Only Fires Once

    Hi,
    I have a TestStand OI that has a callback VI registered for TerminationStateChanged event.  Essentially, I'd like to show an image anytime the user hits the terminate button to shutdown the sequence.  It seems that the first time I run the sequence, everything works fine.  I click terminate during a sequence, TS fires my callback VI -- I trap newTermState 2 (Terminating) and am able to display the image without a problem.  However, it seems that when the user runs the sequence again, the callback VI never fires on a termination.  If I click terminate this time, TS must have received the command because the sequence does in fact terminate... but the callback VI is never called.
    Am I missing something?   Does this callback only work once? 
    Thanks!

    Hi jplotzke,
    I just wanted to clarify from my earlier post that although using the Execution.GetTerminationMonitorStatus function will detect a termination state change in your sequence, you may simply be able to use the Execution.GetStates method instead as it does not require any initialization. Note however that we can use this function without any penalty in this case since the sequence runs inside of the TestStand engine and so there is no performance hit when calling this method. On the other hand, if you were to call this method from a UI, you will be crossing a client/server boundary, which in turn will result in some performance penalty. So if you wanted to make changes to the UI instead of adding extra steps in your sequence, I recommend using the ExecutionViewMgr methods to track the Termination State as it will have the smallest impact on performance.
    I hope this clarifies some questions.
    S_Hong
    National Instruments
    Applications Engineer

  • CEV-Rules only fire once

    Our Change Events Rules fire only once effectively. If we save one record per transaction everything works fine. The CEV-rules are fired, and executed. If, however, we enter 2 records (or more...) per transaction, the CEV-rule is fired twice, but thice for the same record.
    I can see in the trace-files, it does pass the NEED-BR procedure, but when it fires the second time, the same record-data is used as from the first record, resulting in the fact, that one record was not processed.
    We're running forms 6i(6.0.8.24.1) and Headstart patchlevel= PATCH6523

    are you sure you're using a changeListener?
    works OK in this
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    class Testing
      public void buildGUI()
        final JTabbedPane tp = new JTabbedPane();
        for(int x = 0; x < 5; x++) tp.addTab(""+(char)(x+65),new JPanel());
        JFrame f = new JFrame();
        f.getContentPane().add(tp);
        f.setSize(300,200);
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
        tp.addChangeListener(new ChangeListener(){
          public void stateChanged(ChangeEvent ce){
            JOptionPane.showMessageDialog(null,tp.getTitleAt(tp.getSelectedIndex()));
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }post a sample program so we can see what you're doing
    (by compiling/running the sample program)

  • Lightswitch HTML Client - beforeApplyChanges only fires once

    Hi,
    I have a standard Add/Edit screen created by Visual Studio with the standard save button in the top right-hand corner. In my beforeApplyChanges function I have the following code:
    if (!screen.OrderAllocation.OfflineAdType) {
    screen.findContentItem("OfflineAdType").validationResults = [
    new msls.ValidationResult(
    screen.OrderAllocation.details.properties.OfflineAdTypes,
    "This is a required field")];
    return false;
    This fires correctly if someone tries to save the object without an OfflineAdType. However, if they then correct the error by editing it within the screen, and then click on the standard save button - a message box pops up saying there's validation errors
    on the page. BeforeApplyChanges isn't called.
    How do I clear these validation errors beforehand?

    You need to clear the validation results.  You can also add a change listener to update any time the value changes.  See the answer to this post. 
    https://social.msdn.microsoft.com/Forums/en-US/08af462d-a094-44b2-bf3c-a3cd5f7a40a9/hmtl-client-screen-validation?forum=lightswitch

  • Making the subject only black and white?

    Still kind of new to AF (using AF CC)  and here's one I can't figure out. I've been through the manual and the You Tube tutorials, but no help. I have a color shot of a room that a man walks through. I want the room to remain in color, but the walking man to be black and white (sort of a ghost thing I guess). Other then many hours of rotoscoping, is there a simple way to do this? That's it. Thanks for any help!

    Try using Rotobrush to separate the subject from the background.  You won't have a single bit of luck with Rotobrush unless you read up on it and run tutorials.  In AE Help, use the search term rotobrush and a boatload of useful information appears.
    Got the subject all rotoed nicely?  Make the subject B&W and put it over the original color shot.

  • IO_ERROR event only fires for first bad url

    This is my first Flash application, so please bear with me.
    In the below example, I have a number of files that I load
    using loaders.
    However, when I have more than one bad url (missing file,
    wrong domain, ...) the IO_ERROR event only fires once. For all
    subsequent bad urls, the system does nothing and just hangs (when
    loading consecutively).
    A workaround is to load all images silmultaneously, but I
    still want to know what the problem is.

    Thought I'd post the solution here.
    In the end, the problem was: loading a file from an
    non-existent domain triggered no errors.
    It's apparantly a problem with FF and OS/X
    http://tinyurl.com/5q87n3

  • Event only works once

    Hi all!
       I'm trying to do a movieclip that has 2 buttons that change the content of a flvplayer.
       The problem is that the buttons only work once, after that the event listener isn't triggered (I think) I have no removeEventListener in my code for those events so I'm totally lost as to why is this happening.
       My code is this:
    stop();
    var correr:Boolean = true;
    Globals.vars.videoP = CM_player;
    SnowManInst.addEventListener(MouseEvent.MOUSE_DOWN, mudarVideo_SM);
    bananaKingInst.addEventListener(MouseEvent.MOUSE_DOWN, mudarVideo_BK);
    addEventListener(MouseEvent.MOUSE_DOWN, pararFilme);
    function pararFilme(e1:MouseEvent){
        trace("pararFilme "+Globals.vars.videoP);
        Globals.vars.videoP.stop();
        correr = false;
        removeEventListener(MouseEvent.MOUSE_DOWN, pararFilme);
        addEventListener(MouseEvent.MOUSE_DOWN, correrFilme);
    function correrFilme(e1:MouseEvent){
        trace("correrFilme");
        Globals.vars.videoP.play();
        correr = true;
        removeEventListener(MouseEvent.MOUSE_DOWN, correrFilme);
        addEventListener(MouseEvent.MOUSE_DOWN, pararFilme);
    function mudarVideo_BK(e1:MouseEvent){
        trace("mudar video BK");
        Globals.vars.videoP.stop();   
        gotoAndStop(2);
    function mudarVideo_SM(e1:MouseEvent){
        trace("mudarVideo_SM");
        Globals.vars.videoP.stop();   
        gotoAndStop(3);
    Any help would be greatly appreciated.

    it's not clear what you're trying to accomplish with that code but there are a few reasons that might fail.
    to starty, you should understand that first a button event is dispatched, then a main timeline event is dispatched (and the main timeline listener toggles between two listener functions) and finally you go to a different frame and any code in the other frame is executed.
    so, that's a pretty screwy setup.  you should remove the main timeline listeners and their functions and it's not clear you need to direct the main timeline to another frame.

  • SQL Query - Where cause where only exists once...?

    I have a query/result set that I'm trying to query/filter.
    What I need is, in two of the 5 columns in the resultset, I need returned where the record only exists once. In the other 3, they have to meet certain criteria.
    So, logically it would true for all: give me results where results in column 1,2 only exist once AND column3 is null and column3 is null and column5 =Server
    Not sure if this make sense....? :/
    a
    Edited by: Topher34 on Mar 11, 2010 4:18 PM

    Topher34 wrote:
    Not sure if this make sense....? :/
    I can give a example table....how do I ''code'' the script?An example certainly would help (also please mention your database version).
    Put your example between the tag (put the tag before and after your example).
    Use CTAS or CREATE TABLE + INSERT statements, and the desired output you want from that.
    See the FAQ for more information regarding tags:
    http://forums.oracle.com/forums/help.jspa (scroll down a bit)
    CTAS =  Create Table As Select ....<your query>.
    It is less work than providing CREATE TABLE and INSERT INTO statements.
    If your database version allows for it, you can achieve the same using the WITH clause.
    But in the end: providing working and (small but complete) examples will boost the response to your question.
    Also, chances are that when you put up an example, you'll see the answer yourself.
    +edit+
    Never mind, bedtime for me ;)
    Edited by: hoek on Mar 11, 2010 11:26 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How come this sound only plays once?

    Here is a program that illustrates what I am doing:
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.sound.sampled.*;
    public class soundApp extends JFrame
        JButton button;                
        Clip clip;
        public soundApp()
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(300,300);
            File file = new File("tada.wav"); 
            try
                AudioInputStream audiosource = AudioSystem.getAudioInputStream(file);
                DataLine.Info info =
                    new DataLine.Info(Clip.class, audiosource.getFormat());
                clip = (Clip)AudioSystem.getLine(info);  
                clip.open(audiosource);
            catch(UnsupportedAudioFileException e){}
            catch(LineUnavailableException e){}
            catch(IOException e){}
            button = new JButton("Play sound");
            button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e){
                if(e.getActionCommand().equals("Play sound"))
                    clip.start();   //HERE IS WHERE I START IT....sorry for caps.
            Container contentpane = getContentPane();
            contentpane.add(button);
            setVisible(true);
      public static void main(String[] args)
          soundApp soundapp = new soundApp();
    }How come the clip only plays once?

    well the answer is simple, because once the clip will stop the sound will stop too. you have not used any loop or anything that shows that the clip should go on forever. you can give some condition like play the clip unless some other button is pressed or some othe action is performed or so on. just use while or any or iterative or conditional statement to get your ay out.

  • HT5463 my phone log also shows the call that made it through only called once...shouldn't it have shown twice?

    iphone 5 issue with DO NOT DISTURB feature.  Feature is ON, allowing FAVORITES to be able to call, I RECEIVED A TELEMARKETING CALL THAT BYPASSED THE SETTING as my phone log only shows they called once and the phone rang and I answered.  Shouldn't the phone log show they called twice?  Otherwise I have to consider this another failure by Iphone 5.

    Here's an update. I just did the Disk Utility tests, of basically all the elements that appear on the left of the window (3 available selections), including the Macintosh HD one. They all passed the verifying and repairing processes, no warnings or errors whatsoever. Yay. The point is, yesterday I was looking at my photos from the Finder. I wasn't doing anything at all, really, not even moving the cursor, when I suddenly heard the HDD making the working-noise without stopping, just that constant scratchy noise. This went for something like 7 seconds straight, and at the very next moment, it started making a consecutive and tempoed stream of this same sound, but a little bit less intense, with interlapses of about a sec. This continued for about a whole minute. I'd like to know if things are really fine.
    As I previously described, the guys at iShop almost don't want me there anymore, or at least that's what their distanced attitudes get my into thinking. I visited the place some days ago, to look at the new iPod Touch pretty quickly, and I clearly felt that the guards were watching me closely, you know, with a hostile mannerism, the kind of stance that you use, with arms folded, to look kind of intimidating. I really didn't do anything to deserve that paranoic and ridiculous behavior. What happened was, a bit hottened discusion with the manager, when I was telling him I needed a replacement, and he really wasn't giving me an empathetic and understanding attitude.
    If a call to Apple Support is required soon, and my computer needs to be repaired or the HDD replaced, they'll most likely send me there, since it's the most prominent place of recommendation. Sincerely speaking, they do seem like the most prepared personel, and they aren't great per se. If that is so, I really, really hope that the hard drive is the only part or detail that needs some technical considering, and deserves my stress.
    Thanks for your consideration, so far so good.

  • How to make users to select the date from calendar control my making the date field read only in date time control in external list in sharepoint 2010

    How to make users to select the date from calendar control only, by my making the date text field read only (don't want to let users type the date) in date time control in external list in sharepoint 2010. I am looking for a solution which can
    be done through sharepoint desginer / out of the box.
    thanks.

    Congratulate you got the solution by yourself. I am new to a
    WinForms calendar component, I feel so helpless on many problems even I'd read many tutorials. This question on the
    calendar date selection did me a great favor. Cheers.

  • I just got the iPhone 5 and noticed that the message alerts will only alert once . I have it set up as 3 times and its not working . Please help. I'm running 6.0.2 and I really starting to get ****** off with apple products

    I just got the iPhone 5 and noticed that the message alerts will only alert once . I have it set up as 3 times and its not working . Please help. I'm running 6.0.2 and I really starting to get ****** off with apple products

    Instead of getting annoyed, read the User's Guide and try basic troubleshooting.

  • How to float a landing page to capture email address, only shown once per visitor to the site, and not on return visits?

    I would like to float a landing page to capture email addresses, that is only shown once per visitor to the site, and not on return visits OR after they submit their email not to be asked again.
    thanks guys!

    Hi Scott,
    Thanks a lot for the advice.
    Actually I added user names to the apex_access_control table and assigned each user the desired privilege but did not notice that I should do the following setting.
    *Access Control Administration > [RUN] > Set Application Mode: Restricted access.*
    Thanks,
    Guy

  • The iphone 4 only rings once?

    the iphone 4 only rings once . before it was OK
    Can somebody thell me how to fix this?

    That is a carrier setting contact them for how to change.

  • I am using duel thunderbolt displays with a MacBook Pro. I only have the option to have sound come from one or the other. Has anyone thought of making the left channel come from both speakers on the left Monitor and the same of the right? If yes, how is t

    I am using duel thunderbolt displays with a MacBook Pro. I only have the option to have sound come from one or the other. Has anyone thought of making the left channel come from both speakers on the left Monitor and the same of the right? If yes, how is that done? The MacBook Pro could even be a center channel if configured in that order.

    See the following thread on the same topic:
    2 Thunderbolt displays   MBP = sound coming from both displays?

Maybe you are looking for

  • SSL VPN with machine certificate authentication

    Hi All, I've configured a VPN profile for an Anyconnect VPN connection on my test environment. I've enabled AAA (RSA) and certificate authentication, configured the RSA servers correctly and uploaded the root and issuing certificates. I managed to ge

  • Error  While Genrating Document  in ADOB Form

    Hello Everybody , When  I used  SFP  tcode  for  Design  ADOB  Form  Layout   I am getting  Error   "   Error While Generating Document  "  . Plz Sugget me  how to resolved it   ... Regards, Sandeep Jadhav

  • How to Disable Image Processor Dialog Box?

    Hey guys, It's driving me nuts. I'm trying to create an action where I move image folder onto a droplet, which is image processor script and have all psd files turned to images. Howerver, each time I get the dialog box asking me input/output folder i

  • Speedstep-centrino in beyond doesn't work

    Hi, I have Arch running on an inspiron 9400 with a core duo. If I boot into the normal arch kernel, cpu scaling works fine. But, in beyond it keeps saying: FATAL: Error inserting speedstep_centrino (location of *.ko file): No such device when I try t

  • How to set the default button of an ALERT

    Can someone help me how to set the alert propety to change the default button from button1 to button2.Not from the prioperty palette, but inside the code using like set_alert_property.I am using the Oracle Forms 10g. Thanks in advance. Srini