Solved

JDialog / JColorChooser crash JVM after applet reload

Posted on 2006-11-09
18
435 Views
Last Modified: 2008-01-09
Hello experts,

I have an Applet which uses a JColorChooser in a JDialog. When I bring up the color chooser, it sometimes crashes the JVM.

After some investigation, I realised it only did it after the Applet has been reloaded (either by page refresh, or by loading it with different parameters).

The whole browser locks up and you have to kill the browser process. The problem seems unique to Windows machines - it doesn't do it on a mac.

Any idea what's causing it?

Thanks,
Matt.
0
Comment
Question by:mb2297
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 4
18 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 17911909
The combination Windows <-> *Chooser has some weird problems with JAVA 5.0
JFileChooser is another example to hang the application.

;JOOP!
0
 

Author Comment

by:mb2297
ID: 17913370
Well damn. Are there any workarounds?
0
 

Author Comment

by:mb2297
ID: 17913419
Or bug reports even, I can't seem to find anything on the web.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 24

Expert Comment

by:sciuriware
ID: 17913742
0
 

Author Comment

by:mb2297
ID: 17914306
That doesn't really help. I've already searched the bug database and not found anything. Is it a well documented bug or not?
0
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 250 total points
ID: 17914401
No, but even our beloved moderator experienced it.

;JOOP!
0
 

Author Comment

by:mb2297
ID: 17915254
If it's been experienced by other people then surely there's some information out there about how to avoid it, or how others solved the problem.

Who's our beloved moderator, and did they write down the problem (or preferably solution) anywhere?
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17915459
Moderator == Page Editor (look left).
I think we all should bring a sharp case forward and enter it in that SUN database.

;JOOP!
0
 
LVL 20

Expert Comment

by:Venabili
ID: 17921822
Which version of JVM you are using? And what OS do you have? And is it happening ONLY on windows 2000/2003/IE 6... Because in Firefox we never saw this... Neither I saw it from my home Win XP machine - but we never tested really hard on XP

It is not documented.. and I never had thr time to build an easy example to submit...
And I never solved it... it was for an internal site so the client decided to live with it...


0
 

Author Comment

by:mb2297
ID: 17927553
Thanks for the response Venabili.

The OS is XP Pro, and it happens routinely after the applet has been reloaded at least once, in IE *and* firefox/mozilla. Opera however, is fine.

A bit more detail on the App:

It basically allows users to draw on a background image. The colorchooser is used on a few occasions. Once a line is drawn, it's displayed in a JTable which has a color renderer/editor for one of the columns - so you can change the color of each line individually. You can also change the default color of all new lines to be drawn.

I've tried restricting it so there's only the default color chooser, but the problem persists. I've also tried to build a demo Applet but haven't managed to reproduce the bug in it yet.

Any further information greatly appreciated. I'll keep you posted...

Thanks,
Matt.
0
 
LVL 20

Expert Comment

by:Venabili
ID: 17928454
Which version of JVM you are using?

Yeah - when you get some elements out, the error stop hapenning... And I cannot post 5000+ lines in the Sun bigbase :)
0
 

Author Comment

by:mb2297
ID: 17928811
Sorry, it's Java 1.5.0_9.

Were you finding that the bug was consistent, or intermittent?

Matt.

0
 
LVL 20

Expert Comment

by:Venabili
ID: 17937253
See the old thread we were having on this: http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_22025491.html

Well... it depended. On Solaris where I was testing it was hanging with no real pattern but was always returning back at one point

And the repeating case that I had started not to happen every 3rd or 4th time...
0
 

Author Comment

by:mb2297
ID: 17940142
Found it!

The JPanel that contained my JColorChooser was a Singleton. Something must have been getting lost in the JVM. If you instantiate a new version every time you need to use it, the problem goes away.

Do you think this was the same problem you experienced before? Is it worthy of a bug-report, do you think?

Posted below is some code that works. Change ColorPanel to be a singleton, and it crashes every time.

Thanks,
Matt.

/*
 * AppFrame.java
 */

package com.matt.ilab.core;

import javax.swing.*;

import com.matt.ilab.ui.ColorPanel;
import java.awt.*;

public class AppFrame extends javax.swing.JApplet {
      
      //my panels
      private ColorPanel colorPanel;
      private JPanel container;
      
   
      public void init() {
            
            container = new JPanel();
            colorPanel = new ColorPanel();
            
            container.setLayout(new java.awt.BorderLayout());
            container.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
            
            colorPanel.setPreferredSize(new java.awt.Dimension(250, 400));
            
            container.add(colorPanel,BorderLayout.EAST);
            container.add(new JLabel("version 8 - no more instances"));
            
            getContentPane().add(container);

      }

}

------------------------------------------------

package com.matt.ilab.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ColorPanel extends JPanel implements ActionListener {

      protected static final String EDIT = "edit";

      private JColorChooser colorChooser;
      private Dialog dialog;
      
      private Color defaultColor = new Color(0,0,0);
      
      private JButton changeDefaultColor;
      
      private JLabel buttonColor;

      public ColorPanel() {
            super();

            changeDefaultColor = new
            colorChooser = new JColorChooser();
            dialog = JColorChooser.createDialog(changeDefaultColor,
                                        "Pick a Color",
                                        true,  //modal
                                        colorChooser,
                                        this,  //OK button handler
                                        null); //no CANCEL button handler
            
             changeDefaultColor.setActionCommand(EDIT);
            changeDefaultColor.addActionListener(this);
            changeDefaultColor.setPreferredSize(new Dimension(20,20));
            
            changeDefaultColor.setLayout(new BorderLayout());
            changeDefaultColor.setMargin(new Insets(3, 3, 3, 3)); // This is to show the button's border properly)
                   
            buttonColor = new JLabel();
            buttonColor.setBackground(this.defaultColor);
            buttonColor.setOpaque(true);
            changeDefaultColor.add(buttonColor);
            
            JPanel colorOptions = new JPanel();
            colorOptions.setMaximumSize(new Dimension(250,250));
            JLabel colorTitle = new JLabel("Change default color: ");
            
            colorOptions.add(colorTitle);
            colorOptions.add(changeDefaultColor);
            
            this.add(colorOptions);

      }
      
      public void actionPerformed(ActionEvent e) {
              if (EDIT.equals(e.getActionCommand())) {

                        dialog.setVisible(true);

            } else {
              
                  //ok button pushed
                  this.defaultColor = colorChooser.getColor();
                  buttonColor.setBackground(colorChooser.getColor());
           
            }
      }
}
0
 
LVL 20

Accepted Solution

by:
Venabili earned 250 total points
ID: 17940641
Nope - I had been trying this.. and as I said  it had never be consistent for me..

Yeah - worth reporting I think :)
0
 

Author Comment

by:mb2297
ID: 18165825
Sorry guys - I'd forgotten about this question. Points to both of you for your help.

Thanks,
Matt.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 18166056
SUN must be sorry; thanks.

;JOOP!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

623 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