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.
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.
ASKER
Well damn. Are there any workarounds?
ASKER
Or bug reports even, I can't seem to find anything on the web.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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!
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...
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...
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.
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 :)
Yeah - when you get some elements out, the error stop hapenning... And I cannot post 5000+ lines in the Sun bigbase :)
ASKER
Sorry, it's Java 1.5.0_9.
Were you finding that the bug was consistent, or intermittent?
Matt.
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...
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...
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.ColorPane l;
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(Border Factory.cr eateEmptyB order(5,5, 5,5));
colorPanel.setPreferredSiz e(new java.awt.Dimension(250, 400));
container.add(colorPanel,B orderLayou t.EAST);
container.add(new JLabel("version 8 - no more instances"));
getContentPane().add(conta iner);
}
}
-------------------------- ---------- ---------- --
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 (changeDef aultColor,
"Pick a Color",
true, //modal
colorChooser,
this, //OK button handler
null); //no CANCEL button handler
changeDefaultColor.setActi onCommand( EDIT);
changeDefaultColor.addActi onListener (this);
changeDefaultColor.setPref erredSize( new Dimension(20,20));
changeDefaultColor.setLayo ut(new BorderLayout());
changeDefaultColor.setMarg in(new Insets(3, 3, 3, 3)); // This is to show the button's border properly)
buttonColor = new JLabel();
buttonColor.setBackground( this.defau ltColor);
buttonColor.setOpaque(true );
changeDefaultColor.add(but tonColor);
JPanel colorOptions = new JPanel();
colorOptions.setMaximumSiz e(new Dimension(250,250));
JLabel colorTitle = new JLabel("Change default color: ");
colorOptions.add(colorTitl e);
colorOptions.add(changeDef aultColor) ;
this.add(colorOptions);
}
public void actionPerformed(ActionEven t e) {
if (EDIT.equals(e.getActionCo mmand())) {
dialog.setVisible(true);
} else {
//ok button pushed
this.defaultColor = colorChooser.getColor();
buttonColor.setBackground( colorChoos er.getColo r());
}
}
}
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.ColorPane
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(Border
colorPanel.setPreferredSiz
container.add(colorPanel,B
container.add(new JLabel("version 8 - no more instances"));
getContentPane().add(conta
}
}
--------------------------
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
"Pick a Color",
true, //modal
colorChooser,
this, //OK button handler
null); //no CANCEL button handler
changeDefaultColor.setActi
changeDefaultColor.addActi
changeDefaultColor.setPref
changeDefaultColor.setLayo
changeDefaultColor.setMarg
buttonColor = new JLabel();
buttonColor.setBackground(
buttonColor.setOpaque(true
changeDefaultColor.add(but
JPanel colorOptions = new JPanel();
colorOptions.setMaximumSiz
JLabel colorTitle = new JLabel("Change default color: ");
colorOptions.add(colorTitl
colorOptions.add(changeDef
this.add(colorOptions);
}
public void actionPerformed(ActionEven
if (EDIT.equals(e.getActionCo
dialog.setVisible(true);
} else {
//ok button pushed
this.defaultColor = colorChooser.getColor();
buttonColor.setBackground(
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry guys - I'd forgotten about this question. Points to both of you for your help.
Thanks,
Matt.
Thanks,
Matt.
SUN must be sorry; thanks.
;JOOP!
;JOOP!
JFileChooser is another example to hang the application.
;JOOP!