Is this a bug in Swing in JDK1.6/JDK1.7 but not in JDK1.5?

I have an application for which GUI was developed in Java Swing JDK1.5.I am planning to upgrade the JDK to JDK1.6 but doing so produces problem for me.
Problem Statement : If I open few dialogs(say 10) and dispose them and than call method 'getOwnedWindows()' , it returns 0 in JDK1.5 but returns 10 in JDK1.6. As in JDK1.6 it returns 10, my algorithm to set focus is not working correctly as it is able to find invlaid/disposed dialogs and try to set the focus on it but not on the correct and valid dialog or component because algorithm uses getOwnedWindows() to get the valid and currently open dialog.
Can anyone suggest me the workaround to avoid this problem in JDK1.6?
Following piece of code can demonstrate the problem.
Custom Dialog Class :
import javax.swing.JDialog;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
public class CustomDialog extends JDialog implements ActionListener {
    private JPanel myPanel = null;
    private JButton yesButton = null;
    private JButton noButton = null;
    private boolean answer = false;
    public boolean getAnswer() { return answer; }
    public CustomDialog(JFrame frame, boolean modal, String myMessage) {
     super(frame, modal);
     myPanel = new JPanel();
     getContentPane().add(myPanel);
     myPanel.add(new JLabel(myMessage));
     yesButton = new JButton("Yes");
     yesButton.addActionListener(this);
     myPanel.add(yesButton);     
     noButton = new JButton("No");
     noButton.addActionListener(this);
     myPanel.add(noButton);     
     pack();
     setLocationRelativeTo(frame);
     setVisible(true);
     //System.out.println("Constrtuctor ends");
    public void actionPerformed(ActionEvent e) {
     if(yesButton == e.getSource()) {
         System.err.println("User chose yes.");
         answer = true;
         //setVisible(false);
     else if(noButton == e.getSource()) {
         System.err.println("User chose no.");
         answer = false;
         //setVisible(false);
    public void customFinalize() {
         try {
               finalize();
          } catch (Throwable e) {
               e.printStackTrace();
}Main Class:
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionEvent;
import java.awt.FlowLayout;
import java.awt.Window;
public class TestTheDialog implements ActionListener {
    JFrame mainFrame = null;
    JButton myButton = null;
    JButton myButton_2 = null;
    public TestTheDialog() {
        mainFrame = new JFrame("TestTheDialog Tester");
        mainFrame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {System.exit(0);}
        myButton = new JButton("Test the dialog!");
        myButton_2 = new JButton("Print no. of owned Windows");
        myButton.addActionListener(this);
        myButton_2.addActionListener(this);
        mainFrame.setLocationRelativeTo(null);
        FlowLayout flayout = new FlowLayout();
        mainFrame.setLayout(flayout);
        mainFrame.getContentPane().add(myButton);
        mainFrame.getContentPane().add(myButton_2);
        mainFrame.pack();
        mainFrame.setVisible(true);
    public void actionPerformed(ActionEvent e) {
        if(myButton == e.getSource()) {
               System.out.println("getOwnedWindows 1 " + mainFrame.getOwnedWindows().length);
             createMultipleDialogs();
            int i = 0;
               for (Window singleWindow : mainFrame.getOwnedWindows()) {
                    System.out.println("getOwnedWindows " + i++ + " "
                              + singleWindow.isShowing() + " "
                              + singleWindow.isVisible() + " " + singleWindow);
               System.out.println("getOwnedWindows 2 " + mainFrame.getOwnedWindows().length);
            //System.gc();
               System.out.println("getOwnedWindows 3 " + mainFrame.getOwnedWindows().length);
            //System.gc();
               System.out.println("getOwnedWindows 4 " + mainFrame.getOwnedWindows().length);
        } else if (myButton_2 == e.getSource()) {
               System.out.println("getOwnedWindows now: " + mainFrame.getOwnedWindows().length);
     public void createMultipleDialogs() {
          for (int a = 0; a < 10; a++) {
               CustomDialog myDialog = new CustomDialog(mainFrame, false,
                         "Do you like Java?");
               myDialog.dispose();
               myDialog.customFinalize();
    public static void main(String argv[]) {
        TestTheDialog tester = new TestTheDialog();
}Running the above code gives different output for JDK1.5 and JDK1.6
I would appreciate your help in this regards.
Thanks

Fix your algorithm to check if the windows are displayable/showing instead of assuming they are?

Similar Messages

  • Accelerator key - is this a bug in Swing?

    Hello to everyone.
    I've written this Swing app which has JMenu.
    Anyway, i have set accelerator keys on most of JMenuItems but here is what is not working:
    JMenuItem exPaperXML = new JMenuItem("Paper XML");
    exPaperXML.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0));As you can see, I tried to set F10 to be accelerator key for this JMenuItem.
    It doesn't work. It doesn't fire exPaperXML.actionPerformed(..) event, but
    instead it highlights File JMenuItem (which doesn't have accelerator key set at all).
    For example, I have set F9 as accelerator key for another JMenuItem and it works fine.
    What do you think, is this a bug in Swing?
    My JDK version is 1.4.2_05
    Thanks!

    1) Read the JMenuBar API.
    2) Click on the "JMenuBar Key Assignments" link
    3) Click on "Key Java"
    4) Note how F10 is used to select the first item.camickr thank you for quick reply.
    Is there a way to override this default action?
    Thanks.

  • Why does the apps store not accept my ID and password, it works fine to log into this forum and it works for the apple store, but not to log in to buy apps, it just keeps telling me that the id or password is wrong, and I know it isn't

    Why does the apps store not accept my ID and password, it works fine to log into this forum and it works for the apple store, but not to log in to buy apps, it just keeps telling me that the id or password is wrong, and I know it isn't

    I Just signed in to find the answer to this too.  I started having the same trouble today.

  • I payed for my creative cloud membership 9.99 / monthe. bought it this morning. I was able to download Lr, but not Ps. I am wondering why is asking me to pay antoher 9.99 if I got the student deal. Can you please help. thank you.

    I payed for my creative cloud membership at 9.99/mo. I got it this morning. I was able to download Lr, but not able to download Ps. is asking me to pay again. Why is that, because I got the student packet deal. Can you please help.

    Mariacazarez what is the exact error message you receive when you try to download and install Photoshop?  For information on how to install the Adobe Creative applications included with your membership please see Install and update apps - https://helpx.adobe.com/creative-cloud/help/install-apps.html.

  • Some websites keep asking to enable cookies in my browser when they are and I can't get this sites to see that, they worked fine yesturday but not now, any help

    Some websites keep asking to enable cookies in my browser when they are and I can't get this sites to see that, they worked fine yesterday but not now. I've restarted the browser, restarted the computer, disabled then enabled cookies in the privacy settings and still nothing. Any help?

    Hi,
    Many site issues can be caused by corrupt cookies or cache. In order to try to fix these problems, the first step is to clear both cookies and the cache.
    Note: ''This will temporarily log you out of all sites you're logged in to.''
    To clear cache and cookies do the following:
    #Go to Firefox > History > Clear recent history or (if no Firefox button is shown) go to Tools > Clear recent history.
    #Under "Time range to clear", select "Everything".
    #Now, click the arrow next to Details to toggle the Details list active.
    #From the details list, check ''Cache'' and ''Cookies'' and uncheck everything else.
    #Now click the ''Clear now'' button.
    Further information can be found in the [[Clear your cache, history and other personal information in Firefox]] article.
    Did this fix your problems? Please report back to us!

  • Is this a bug in Swing?

    If anyone could provide help on this ASAP it would be greatly appreciated. I was hoping to use my Swing application in an experiment on Tuesday morning, but I seem to have run into a bug in Swing. I'm hoping I have made a mistake or there is some workaround. Here is a minimal program that demonstrates the apparent bug:
    [http://gist.github.com/113083|http://gist.github.com/113083]
    The bug is this:
    I have a Swing container (in the demo program the contentPane) and I have a list of Swing components (some JLabels in the demo).
    At first the container is showing the first component in my list of components. When I press the JButton "next" the first component is removed from the container, the second component is added to the container, and the container is refreshed (calling validate() and then doLayout() is enough).
    When I press next again the third component is put onto the container. So far so good.
    Now press next again and it cycles back to the first component, which is put onto the container. But the GUI does not refresh, it continues to show the previous component.
    From now on whenever you press Next it will not refresh.
    Resizing or minimising then maximising the window will cause it to refresh to the component that it should be showing.
    The pattern seems to be this: if a component that has previously been shown in a container (but is no longer in it) is placed back into that same container then refreshing the GUI fails.
    Edited by: tchomby on May 17, 2009 11:33 AM

    I wasn't assuming this was a bug in Swing, I was asking whether it was. I had used validate, doLayout etc. to dynamically change a Swing GUI before, and so thought that was how it was done. After constructing a minimal demo it appeared to me that there was something wrong. Yes I am a swing newbie.
    There are so many refresh methods, validate, revalidate, doLayout, repaint, pack, it's pretty confusing. I think that because the new component I was putting in place had exactly the same shape and size as the one it was replacing, then perhaps any calls to the various methods that redo the layout if necessary would have no effect. repaint() does sound like it would have been the right thing. That might explain why calling pack after removing the component, when the container is empty, and then calling it again after adding the component seemed to work.
    Anyway, CardLayout works in my demo, I will use it. Thanks :)
    Edited by: tchomby on May 17, 2009 12:03 PM

  • InsertBeforeEnd works in JDK1.3 but not in JDK1.4

    Any idea why this would work perfectly in JDK1.3 but not JDK1.4?
    logPane = new JEditorPane();
    logPane.setEditable(false);
    HTMLEditorKit k = new HTMLEditorKit();
    doc = (HTMLDocument)k.createDefaultDocument();
    logPane.setEditorKit(k);
    logPane.setDocument(doc);
    logPane.setText("<div id=\"myDiv\"></div>");
    Element convDiv = doc.getElement("myDiv");
    doc.setInnerHTML(convDiv,"<p>Test1</p>"); // This works in both
    doc.insertBeforeEnd(convDiv,"<p>Test2</p>"); // This throws exception
    The setInnerHTML works fine in the JDK's. The insertBeforeEnd throws a "BadLocationException: Invalid insert" in JDK1.4 but works fine in JDK1.3...
    Quite frustrating!

    Well, I finally took a look at the JDK code (GapContent.java). It seems the supposedly "fixed" bug is still there in JDK1.4.0 and JDK1.4.1 (latest) (http://developer.java.sun.com/developer/bugParade/bugs/4496801.html)
    The workaround is to put some characters after the div as follows:
    logPane.setText("<div id=\"myDiv\"></div>&_nbsp_;");
    ( remove the _ in nbsp above )
    Now it works in both JDK's!

  • Key backspace and delete work with JDK1.3.1 and not with JDK1.4

    In JCTable, keys backspace and delete are not working with JDK1.4. It works with JDK1.3.1.

    I have the same problem, but the version within SUN seems imcomplete,what version is ?
    For example I am using the xsl tag library provided by Apache (I know this now deprecated). In its ApplyTag.java it uses XSLTDataSource this is not in the SUN 1.4 distribution so it falls over. If I add XALAN 1.0.1 it falls over because it on getDefaultLiason() because it starts loading somne classes from rt.jar and some from xalan.jar, how are you meant to override this.

  • Why am I finding this when I run disk utility? ACL found but not expected on "Library/Application Support/Apple/ParentalControls/Users"

    I am finding this when I run repair disk permissions in disk utility:
    ACL found but not expected on “Library/Application Support/Apple/ParentalControls/Users”
    Why is there an access control list on parental controls on my MacBook?  I don't use parental controls and I am the only user of this MacBook. I'm an old guy too, so it's not my Mom putting controls on the MacBook! ;-)
    Thanks!
    MacBook Pro 9, 2
    System Version: OS X 10.8.5 (12F45)
    Kernel Version: Darwin 12.5.0
    Boot Mode: Normal

    From the article I posted a hyperlink to in my 1st post (at bottom): You can also usually ignore any "ACL found but not expected..." message. These messages can occur if you change permissions on a file or directory; they are accurate, but generally not a cause for concern.

  • I have selected calendars on my iPhone and macbook to synch with icloud. This works if I enter items on the phone, but not if they are entered on the macbook. Any suggestions why this is happening and how to fix it?

    I have selected calendars on my iphone and macbook to synch using icloud. If I enter an item on the iphone, it appears on the macbook calendar but not the other way round. Any suggestions why this is happening and how to fix it?

    Dartiesdad wrote:
    Hmmmm  Snow Leopard and iCloud.... not usually workable but here is an article that might be helpful.
    http://reviews.cnet.com/8301-13727_7-57511534-263/how-to-set-up-icloud-services- in-snow-leopard/
    10.7.5 is not Snow Leopard so we have to wait and see, the answers to the question I asked will define what it really is.

  • HT1386 When I try to sync a new playlist it won't go onto my iPhone.  When I click "on this phone" the playlist is there on the computer but not on my phone.

    I cannot get new playlists to sync on my phone.  I could yesterday.  When I click "on this phone" the playlist shows up on the main computer but not on my phone.

    As I said, some items cannot be purchased with an existing credit on an account no matter how much it is.  It can only be purchased with a charge to a credit card.

  • Is this a bug, or am I stupid? (ok, but still...)

    Hi - I have a 4GB iPod Nano. I have four small photos that together, add up to 428KB and uploaded them easily. I just added a new song, and iTunes removed the photos from iPod. When I try to put them back, I'm told that "Some photos were not copied to the iPod because there was not enough free space on the iPod to hold your photos and albums." My iPod tells me that I have 3.7GB Capacity, and 10.7MB Available. The documentation tells me that "You need to have about as much free space on your hard drive as the size of your collection of photos." 428K should fit easily into 10.7MB, so why can't I put my photos back on the iPod?
    Thanks!

    cor-el:
    Thanks for the suggestion. I already tried rebuilding that file as well and it didn't help. Also, all the changes I make are retained from session to session in terms of placement and what's shown/hidden, it's just the contents of the bookmark toolbar that disappear. The toolbar is still there and I can drag things to it, but again, they disappear after restarting the browser.
    edit (clarification):
    When I say the items disappear, I mean they are no longer visible or clickable. They are still there in the sense that they appear in the Bookmark menu and if I move the Bookmark Toolbar from its own toolbar into the space next to the Menu Toolbar, they are then shown.

  • When I go to play a Candy Crush and I want to buy a life or and thing to do with this Game I might get to buy some thing but not all of the thing it say to get the go to the support team at iTunes so can you Help me Please

    I don't know how to get a picture on here for you . It's Candy Crush SAGA Game . I had a 3s iPhone and now I have a 4 iPhone and the game worked fine on the 3 s but it dose not work right on the 4 and bout phone are iPhones and I just need to Help me . I hope you can and if not then all I can do is just delete all of my apple ID so I hope you can Help me Please

    These are user-to-user forums, you are not talking to Apple here. You can contact iTunes support via this page and ask them why the message is appearing : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then probably Purchases, Billing & Redemption

  • Applet works in MS JVM but not in JDK1.4 !

    Running IE 6 SP1 with windows 2000. Everything works well until
    I installed JDK 1.4 recently.
    I have an ancient (JDK 1.1?) applet that refuses to work with JDK 1.4
    But when i disable JDK 1.4 under internet options , it works!
    This is the error
    "java.lang.NoClassDefFoundError; Symantec/tools/awt/multiList"
    If the class is really missing, why was it able to work without JDK 1.4?
    Also note, that Symantec.jar is on the local machine and not on the server. Symantec.jar is a selected compilation of Visual Cafe classes
    that the applet needed.

    It will be better to have Symantec.jar on the server at the same level with your caller applet package. For example
    + Some folder
    |
    + --- yor applet package
    |
    + --- Symantec.jar

  • I'm signed into iTunes but says cannot connect to iTunes at this time. I can play online server games but not update or DL new apps

    I guess to be more specific. I'm signed into iTunes, I can play my usual games,online included. What it won't allow me to do now is update or download new apps. Just says waiting and never goes. I shut the iPad down and restart it, and a message will pop up saying all the game names cannot update at this time , blah blah blah.... What's going on and how do I fix this?

    The Complete Guide to Using the iTunes Store
    http://www.ilounge.com/index.php/articles/comments/the-complete-guide-to-using-t he-itunes-store/
    Can't connect to the iTunes Store
    http://support.apple.com/kb/TS1368
    iTunes: Advanced iTunes Store troubleshooting
    http://support.apple.com/kb/TS3297
     Cheers, Tom

Maybe you are looking for

  • E72 - Unable to set up e-mail mailbox after firmwa...

    Hi all, I have a newly acquired E72-1 which has been updated to the latest firmware version 051.018. I'm trying to set up the e-mail function on my E72 but getting nowhere. I keep getting to the enter e-mail details/password etc page then-nothing. Th

  • How to save error message that arises during invocation

    Hi, If any error raises in between the process, how can i save the error status into db adapter field. For example, I will receive a input from db adapter and I will send this input to a webservice which invokes further activities , my question is if

  • ORA-12505 on Oracle Database 10g Express Edition: TNS:listener

    In Developer3, trying to connect to Oracle Database 10g Express Edition give me: Listener refused the connection with the following error: ORA-12505 TNS:listener does not currently know of SID given in connect descriptor Vendor code 12505 Edited by:

  • How to change the model of JSpinner

    Hello, just want to ask how to change the model of a JSpinner during run time... I have an existing JSpinner example: SpinnerNumberModel model = new SpinnerNumberModel( 2, 2, 4094, 1); jSpinner = new JSpinner(model); if (changeLimitTo255 == true) { m

  • Adding more space

    so i have windows installed through boot camp and it works fine, but i realized i need more hard drive space than just the 5gb i originally partitioned, is there a way to add more HD space without uninstalling windows xp? or if i do uninstall it then