Why does the check box untick itself?

I have a program which has a GUI control that I designed. It consists of several check boxes inside a panel, the user can tick one or more of them. There are various methods to get all the selections, untick boxes in code etc. In one place in my software, I need a dialog box to appear when the user ticks a box. So I got my control to raise a property change event whenever one of the check boxes is ticked or unticked. I then catch this in another part of the code, and cause a dialog to appear which asks the user for further options.
My problem is this: for some strange reason, when the dialog appears, it is causing the check box to be unticked again immediately after it is ticked. I have prepared a simplified version of the problem code, below. If you comment out the call to ticking(), then it works ok (but the dialog doesn't appear obviously). Has anyone got any ideas, please?
import java.awt.GridLayout;
import java.awt.event.*;
import java.beans.*;
import java.util.HashSet;
import javax.swing.*;
public class Testing {
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override public void run() {                 
                Testing testing = new Testing();
    public Testing() {
        JFrame fmMain = new JFrame();
        CheckBoxes cb = new CheckBoxes("one", "two", "three");
        cb.addPropertyChangeListener(new PropertyChangeListener() {    
            @Override public void propertyChange(PropertyChangeEvent pce) {
                String category = (String) pce.getPropertyName();
                if(category.equals("ticking")) {            
                    ticking();  //commenting this out means the boxes are ticked ok
        fmMain.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        fmMain.add(cb);
        fmMain.pack();
        fmMain.setVisible(true);
    private void ticking() {
        final JDialog dlg = new JDialog();
        JButton okbutton = new JButton("OK");
        okbutton.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent ae) {
                dlg.dispose();
        dlg.add(okbutton);
        dlg.setModal(true);
        dlg.pack();
        dlg.setVisible(true); 
    class CheckBoxes extends JScrollPane {
        public CheckBoxes(Object... arr) {
            super();
            GridLayout gl = new GridLayout();
            gl.setColumns(1);
            JPanel panel = new JPanel();
            setViewportView(panel);
            gl.setRows(arr.length);
            panel.setLayout(gl);
            ItemListener cl = new ItemListener() {
                @Override public void itemStateChanged(ItemEvent ie) {
                    JCheckBox cbi = (JCheckBox) ie.getSource();
                    String propertyName = cbi.isSelected() ? "ticking" : "unticking";     
                    System.out.println("Item event: "+propertyName);
                    CheckBoxes.this.firePropertyChange(propertyName, null, cbi.getText());
            HashSet data = new HashSet();
            for(Object o: arr) {
                if(!data.contains(o)) {
                    JCheckBox candidate = new JCheckBox(o.toString());
                    panel.add(candidate);
                    candidate.addItemListener(cl);
                    data.add(o);
}

Thanks Malcolm, I used the different thread as you suggested and it works fine :).
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.*;
import java.beans.*;
import java.util.HashSet;
import javax.swing.*;
public class Testing {
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override public void run() {                 
                Testing testing = new Testing();
    public Testing() {
        JFrame fmMain = new JFrame();
        CheckBoxes cb = new CheckBoxes("one", "two", "three");
        cb.addPropertyChangeListener(new PropertyChangeListener() {    
            @Override public void propertyChange(PropertyChangeEvent pce) {
                String category = (String) pce.getPropertyName();
                if(category.equals("ticking")) {   
                    ShowDlg sd = new ShowDlg();
                    EventQueue.invokeLater(sd);
        fmMain.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        fmMain.add(cb);
        fmMain.pack();
        fmMain.setVisible(true);
    class CheckBoxes extends JScrollPane {
        public CheckBoxes(Object... arr) {
            super();
            GridLayout gl = new GridLayout();
            gl.setColumns(1);
            JPanel panel = new JPanel();
            setViewportView(panel);
            gl.setRows(arr.length);
            panel.setLayout(gl);
            ItemListener cl = new ItemListener() {
                @Override public void itemStateChanged(ItemEvent ie) {
                    JCheckBox cbi = (JCheckBox) ie.getSource();
                    String propertyName = cbi.isSelected() ? "ticking" : "unticking";     
                    System.out.println("Item event: "+propertyName);
                    CheckBoxes.this.firePropertyChange(propertyName, null, cbi.getText());
            HashSet data = new HashSet();
            for(Object o: arr) {
                if(!data.contains(o)) {
                    JCheckBox candidate = new JCheckBox(o.toString());
                    panel.add(candidate);
                    candidate.addItemListener(cl);
                    data.add(o);
    class ShowDlg implements Runnable {
        @Override public void run() {
            final JDialog dlg = new JDialog();
            JButton okbutton = new JButton("OK");
            okbutton.addActionListener(new ActionListener() {
                @Override public void actionPerformed(ActionEvent ae) {
                    dlg.dispose();
            dlg.add(okbutton);
            dlg.setModal(true);
            dlg.pack();
            dlg.setVisible(true); 
}Edited by: 892190 on 19-Oct-2011 08:02

Similar Messages

  • Why is the check box for remember passwords grayed out? It used to work now it won't save them.

    Why is the check box for remember passwords grayed out? It used to work now it won't save them.

    It could be because you have Firefox set to not remember any history. Did you do that intentionally? It is set in the Options dialog:
    "3-bar" menu button (or Tools menu) > Options > Privacy
    Perhaps it would work if you choose "Use custom settings for history" and just turn off the specific things you want to turn off.
    Any luck?

  • Encore CS3, why does subtitle bounding box move itself?

    I've imported a subtitle text file into Encore CS3, specifying the bounding box at the initial load.  I've saved the project and exited.  The next time I open the project, the bounding box has moved itself downward and to the right and taken the subtitles with it.  I can find no way to relocate the bounding box, therefore I can no longer access the subtitles to edit them.  I do not know (about to find out) if the built image will also have relocated subtitles.
    Why is this, and what can I do about it?

    They appeared wrong, so I built the image as a test after they appeared wrong.  The image was built correctly.
    As it turns out, it's now an academic discussion.  I found I had already made the subtitle changes I had intended to make when the bounding box went bonkers.  But I have seen this phenomenon once before, a few years ago.  I forget what I did then, possibly blew the subtitle track away and reimported the subtitles.

  • Why does the iPod starts by itself?

    When I plug the earphones into my iPhone 3G, the iPod automatically starts playing songs. Why does that happen then?

    - By restore itsself do you mean that it erases itself and then either sets ups as a new iPod or restores from a iCloud backup or backup on yur computer?
    - You also say that "how can i just make my ipod a hotspot or something?"
    The iPod does not have celluar connectivity so it has to use wifi to connect to the internet. When you first get a new iPod yu can set it up via wifi or by connecting it to a computer that is connected to the internet. Has the iPod been setup already?

  • Why does the font change by itself?

    I use a Mac, and my fonts keep changing. Today they are italic both in the browser and my gmail.

    You can check for corrupted and duplicate fonts and other font issues:
    *http://www.thexlab.com/faqs/multipleappsquit.html - Font Book 2.0 Help: Checking for damaged fonts
    *http://www.creativetechs.com/iq/garbled_fonts_troubleshooting_guide.html

  • Why does the Background Layer unlock itself?

    When I open a picture in PS the first layer is a locked background layer. If I start working in PS it changes automatically to an unlocked Layer 0. I want it to stay as an locked background layer. I have used PS for a few years, and just started happening.

    With the new version of Photoshop if you work on the background layer and do something like click on the add layer mask icon in the layer palette. Since the background layer does not support transparency Photoshop knows you need to convert the background layer to a normal layer so Photoshop automatically does that for you.  If you just paint on the background layer or clear or fill an area, stroke a selection it will remain a background layer  with its transparency locked.  The Background layer is only partially locked so you can work on it as shown by the un-filled in lock icon on the background layer in the layer palette.  If you look here you see layer 2 is unlocked, Layer 1 is fully locked and the background layer is partly locked and has been worked on.

  • I keep getting the message: "what should firefox do with this file" in Windows XP every time I want to download a file, e.g., adobe, excel, etc. How can this annoying message be deleted? The check box to "open file automatically" does not work!

    I keep getting the message: "what should Firefox do with this file" in Windows XP every time I want to download a file, e.g., adobe, excel, etc. How can this annoying message be deleted? The check box to "open file automatically" does not work!

    cor-el,
    Thanks for your prompt reply. However, the sources you gave do not seem to apply exactly to my situation. I have attached some screenshots that show what the dialogue box looks like for a pdf download, and what my settings in the Apps panel of Options are. You will note in the first screenshot that I have checked the box to handle this file type automatically; however, the next time I try to download a file of that type, the same dialogue box appears looking exactly like the one shown, so checking the "automatic" option appears to do nothing. The files to be downloaded from my Gmail messages are not generic or altered file types - they are shown as pdf, doc, docx, etc. So while your intent was good, your post did not help. Thanks anyway.

  • Why does the iTunes 10.4.1 update take me to Apple's download webpage instead of the usual Safari/Quicktime dialog box?

    Why does the iTunes 10.4.1 update take me to to Apple's download webpage (to download a full version of iTunes) instead of the usual Safari/Quicktime pop-up/dialog box where I usually perform the updates?

    iTunes 10.4 and Safari 5.1 contain more than 'just' the OSX Lion-release but stability and security improvements as well.
    For example, here is http://support.apple.com/kb/DL1070 what the Safari 5.1 contains.
    In here http://www.apple.com/macosx/uptodate/ I can't find an "end-date" for the download of the Lion installer.
    Nonetheless, personaly I would download the Lion installer and then copy it (from your Apllications folder) to a secure place (backup harddisk, external hardisk etc.).
    When your IT gives it a go you can then use te Lion installer from inside the Applications folder, but I would also say to make a bootable clone of your current OSX Snow Leopard before starting the Lion installation.
    Stefan

  • Hi, I'm having issues with my airdrop. I have looked in my finder perfrences and didn't see the check box for airdrop. I have a macbook air running on 10.9.4 Mavericks. Does anyone know how to get my airdrop back? Thanks.

    Hi, I'm having issues with my airdrop. I have looked in my finder perfrences and didn't see the check box for airdrop. I have a macbook air running on 10.9.4 Mavericks. Does anyone know how to get my airdrop back? Thanks.

    Mac Basics: AirDrop lets you send files from your Mac to nearby Macs and iOS devices - Apple Support

  • Why does the iphone allow itself to be powered off while the screen is locked?

    Why does the iphone allow itself to be powered off whlie in the lock screen?  This makes it impossible to track if stolen does it not?  Seems like an assinine concept!

    It does, but there's little we regular mortals can do about it. However, you now have something to contribute to Apple via the Feedback Link!

  • Why does siri come on by itself while it sits on the table no one touching it?

    why does siri come on by itself while it sits on the table no one touching it?

    michael jfromtaunton wrote:
    why does siri come on by itself while it sits on the table no one touching it?
    If you're not running iOS 8 as you describe you are not, and Siri keeps coming on, this could be a hardware failure of the Home Button.
    Try these steps:
    Basic Troubleshooting Steps when all else fails
    - Quit the App by opening multi-tasking bar, and swiping the App upward to make it disappear.  (For iOS 6 older, hold down the icon for the App for about 3-5 seconds, and then tap the red circle with the white minus sign.)
    - Relaunch the App and try again.
    - Restart the device. http://support.apple.com/kb/ht1430
    - Reset the device. (Same article as above.)
    - Reset All Settings (Settings > General > Reset > Reset All Settings)
    - Restore from backup. http://support.apple.com/kb/ht1766 (If you don't have a backup, make one now, then skip to the next step.)
    - Restore as new device. http://support.apple.com/kb/HT4137  For this step, do not re-download ANYTHING, and do not sign into your Apple ID.
    - Test the issue after each step.  If the last one does not resolve the issue, it is likely a hardware problem.

  • Why does the keyboard take over and type c's all across the search box (no hands involved)?

    Why does the keyboard take over and type c's across the search box (no hands involved)?

    There are only three possibilities. Either a dangling hand hitting the c key, or if you have a bluetooth keyboard connected and something is pressing a key, or you have some bad harware.  Eliminate the first two, and if you still have the problem, take it in for service or replacement

  • Using Windows 7 and LR 5  when I look at the Keyword List a certain keyword has 7 pictures but when I check the Library Filter with that keyword 350 pictures are shown which includes the 7 pictures that have the keyword.  Why does the Library Filter showi

    Using Windows 7 and LR 5,  when I look at the Keyword List a certain keyword has 7 pictures but when I check the Library Filter with that keyword 350 pictures are shown which includes the 7 pictures that have the keyword.  Why does the Library Filter showing pictures that do not match the query

    Dan,
    Here's what's going on in the catalog you sent me, "Joel & Caitlin's Wedding".  There is the keyword "gwenn", which is explicitly assigned to 7 pics. But keyword "schwartz" has a number of synonyms, including "gwenn", and it is assigned to 25 pics.  There is no overlap between the two sets of pics. 
    I discovered these two occurrences by doing Metadata > Export Keywords, opening the exported file in an editor, and then searching for "gwenn".  I found two occurrences of "gwenn":
    gwenn
    schwartz
        {gwenn}
    From this, you can see that the keyword "schwartz" has 9 synonyms, of which "gwenn" is one.
    The filter criterion "Keywords Contain gwenn" will match the 7 pics that are explicitly assigned the keyword "gwenn", and it will also match the 25 pics assigned the keyword "schwartz", because that keyword has a synonym "gwenn".
    This illustrates the behavior I mentioned above: The criterion "Keywords contains x" will match against any of a pic's assigned keywords, any of those keywords' ancestor keywords, and any of the synonyms of the assigned keywords and their ancestors.
    So LR is operating correctly here, if not in a way that's easy to understand. 
    It appears that you are using the synonyms of "schwartz" to represent individual members of the Schwartz family.  A better way of representing family relationships is to have a parent keyword "Schwartz", with subkeywords for each family member, e.g. "Gwenn Schwartz", "Joe Schwartz", "Jane Schwartz", etc.  Repeating the family name in the subkeywords has a couple of advantages. LR usually only displays the "leaf" name of a keyword, so instead of showing you just "Joe", it will show you "Joe Schwartz", helpful when there are a number of different people whose first name is "Joe".  Also, if you ever export your pics to other software, it may not understand the LR hierarchy and won't show the parent keywords, so again it's more informative to see a keyword named "Joe Schwartz" rather than "Joe".

  • After the new update, why does my Bluetooth keep turning itself on? I keep turning it off, but it still finds a way to turn itself back on

    After the new update, why does my Bluetooth keep turning itself on? I keep turning it off, but it still finds a way to turn itself back on

    hi Apfelwurm,
    why do you say it's not normal.
    it always switches itself on after i update. it just did again, this time for 7.1.2.. i t also will switch on after a restore.
    i never use bluetooth and make sure it's not on for any other reason.
    it's been noticed by others too.
    http://www.forbes.com/sites/kashmirhill/2014/03/12/apple-keeps-turning-bluetooth -on-when-you-update-your-iphone/

  • Why does my signature box appear as "none" instead of the signature I have designated?

    Why does my signature box appear as "none" instead of the signature I have designated?

    Rebuild the Spotlight index. If you try to search now from the magnifying-glass icon in the top right corner of the display, there will be an indication that indexing is in progress.

Maybe you are looking for

  • Driver Issue on Vista x32

    Since I have upgraded to Vista from XP I am having trouble accessing my phone. My phone model is a 7250i and I connected through CA-42 I downloaded the new Nokia PC Suite which is compatible with Windows Vista. I followed instructions to install PC S

  • 1394 net adapter not working in device manager

    I,m running the KT4 Ultra  with fire wire on board with XP prof. Every thing is working fine except in device manager I have two listings for the 1394 net adapter.The first has the yellow explantion mark, Code ten."this device won't start. And the se

  • Run-time box in middle of screen

    For some reason I get this RunTime box in the middle of the screen I am in DeBug Mode in 8.1.0 LabWindows/CVI. in the many systems I have built for the lab at least 2 have this annoying box that pops up when CVI is launched. if clicked on to close or

  • SPM:Misc Queries

    Hi Need help with below queries 1) When  a user with only a SPM role logs into the portal, he can see Spend performance management mentioned 3 times. Can we make it just visible one time? 2) Can we restrict language in SPM UI only  to english? 3) Can

  • Is it possible to have non-rectangular app windows in Java?

    Do all apps have to be rectangular or can I change their shape? Also, is there an icon chooser dialog in java, where I can choose a file and all of its icons will be displayed, allowing me to choose one? If not, does anyone have any suggestions as to