Link to home
Start Free TrialLog in
Avatar of mb2297
mb2297

asked on

JDialog / JColorChooser crash JVM after applet reload

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.
Avatar of sciuriware
sciuriware

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

;JOOP!
Avatar of mb2297

ASKER

Well damn. Are there any workarounds?
Avatar of mb2297

ASKER

Or bug reports even, I can't seem to find anything on the web.
Avatar of mb2297

ASKER

That doesn't really help. I've already searched the bug database and not found anything. Is it a well documented bug or not?
SOLUTION
Avatar of sciuriware
sciuriware

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mb2297

ASKER

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

;JOOP!
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...


Avatar of mb2297

ASKER

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.
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 :)
Avatar of mb2297

ASKER

Sorry, it's Java 1.5.0_9.

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

Matt.

See the old thread we were having on this: https://www.experts-exchange.com/questions/22025491/JFileChooser-constructor-hangs-in-JAVA-5-09.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...
Avatar of mb2297

ASKER

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());
           
            }
      }
}
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mb2297

ASKER

Sorry guys - I'd forgotten about this question. Points to both of you for your help.

Thanks,
Matt.
SUN must be sorry; thanks.

;JOOP!