Solved

JDialog / JColorChooser crash JVM after applet reload

Posted on 2006-11-09
18
419 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
  • 8
  • 5
  • 4
18 Comments
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
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
Comment Utility
Well damn. Are there any workarounds?
0
 

Author Comment

by:mb2297
Comment Utility
Or bug reports even, I can't seem to find anything on the web.
0
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
0
 

Author Comment

by:mb2297
Comment Utility
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
Comment Utility
No, but even our beloved moderator experienced it.

;JOOP!
0
 

Author Comment

by:mb2297
Comment Utility
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
Comment Utility
Moderator == Page Editor (look left).
I think we all should bring a sharp case forward and enter it in that SUN database.

;JOOP!
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 20

Expert Comment

by:Venabili
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
SUN must be sorry; thanks.

;JOOP!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now