InternalError "cannot nest locks"

E

Elrod

I am writing an application that has a "print preview" function. The
preview window uses a JPanel with an extended "paint" function to draw
the various bit of information. Depending upon the page being
previewed, the panel may pass its Graphics object to the paint method
of a component in the form being previewed do draw that component
verbatim to the preview. This works fine until I wish the scale the
Graphics object before drawing the component, at which point, I
recieve the following Exception (the exception shown is actually from
my mini-test application code shown below, not from the full
application I'm developing):

java.lang.InternalError: Win32OSSD_Lock cannot nest locks
at sun.java2d.loops.ScaledBlit.Scale(Native Method)
at sun.java2d.pipe.DrawImage.scaleSurfaceData(DrawImage.java:708)
at sun.java2d.pipe.DrawImage.transformImage(DrawImage.java:172)
at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:54)
at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:736)
at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:147)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2756)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2746)
at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4797)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
at javax.swing.JComponent.paint(JComponent.java:798)
at ipos3.PreviewTest$1.paint(PreviewTest.java:38)
at javax.swing.JComponent.paintChildren(JComponent.java:647)
at javax.swing.JComponent.paint(JComponent.java:817)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:557)
at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4787)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
at javax.swing.JComponent._paintImmediately(JComponent.java:4685)
at javax.swing.JComponent.paintImmediately(JComponent.java:4488)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

The result is the same on every computer I've tried, all running
Windows XP Home or Pro, and Java 1.4.2
Below is a simple application I threw together in an attempt to
isolate the problem.

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

public class PreviewTest extends JFrame implements
java.awt.event.ActionListener{
JButton btnPreview;
JDesktopPane desktop;
JInternalFrame content;
public PreviewTest() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(500,500);
getContentPane().add(desktop = new
JDesktopPane(),BorderLayout.CENTER);
content = new JInternalFrame("Testing");
content.setSize(400,400);
content.getContentPane().add(new JTable(
new String[][] {
{ "0,0","0,1","0,2" },
{ "1,0","1,1","1,2" },
{ "2,0","2,1","2,2" }
},
new String[] { "Col 0","Col 1","Col 2" }
));
desktop.add(content,1);
content.show();
getContentPane().add(btnPreview = new
JButton("Preview"),BorderLayout.NORTH);
btnPreview.addActionListener(this);
}

public void actionPerformed(java.awt.event.ActionEvent e) {
JInternalFrame preview = new JInternalFrame("Preview") {
public void paint(Graphics g) {
super.paint(g);
g.translate(20,20);
// The following line is what's causing the problem
// comment it out, and the preview button works
((Graphics2D)g).scale(0.5,0.5);
content.getContentPane().paint(g);
}
};
preview.setSize(350,350);
desktop.add(preview,1);
preview.show();
}

public static void main(String[] args) {
new PreviewTest().show();
}
}
 
A

ak

public void actionPerformed(java.awt.event.ActionEvent e) {
JInternalFrame preview = new JInternalFrame("Preview") {
public void paint(Graphics g) {
super.paint(g);
g.translate(20,20);
// The following line is what's causing the problem
// comment it out, and the preview button works
((Graphics2D)g).scale(0.5,0.5);
content.getContentPane().paint(g);
}
};
this looks a little bit ugly
no need to override JInternalFrame's paint() - override paint() of JPanel
and set it as contentPane for your JInternalFrame:

public void actionPerformed(java.awt.event.ActionEvent e) {
JPanel panel = new JPanel() {
protected void paintComponent(Graphics g) {
g.translate(20, 20);
((Graphics2D) g).scale(0.5, 0.5);
super.paintComponent(g);
}
};

JInternalFrame preview = new JInternalFrame("Preview");
preview.setContentPane(panel);

preview.setSize(350, 350);
desktop.add(preview, 1);
preview.show();
}
};
 
E

Elrod

ak said:
this looks a little bit ugly
no need to override JInternalFrame's paint() - override paint() of JPanel
and set it as contentPane for your JInternalFrame:

public void actionPerformed(java.awt.event.ActionEvent e) {
JPanel panel = new JPanel() {
protected void paintComponent(Graphics g) {
g.translate(20, 20);
((Graphics2D) g).scale(0.5, 0.5);
super.paintComponent(g);

// added by Elrod
content.getContentPane().paint(g);
// end alteration
}
};

JInternalFrame preview = new JInternalFrame("Preview");
preview.setContentPane(panel);

preview.setSize(350, 350);
desktop.add(preview, 1);
preview.show();
}
};

Your revised example doesn't do anything towards the actual preview. If you
add:
content.getContentPane().paint(g);
after the overridden paintComponent's super call, so that the component is
shown in the preview, you get the same error as before.
I have, however, figured out a hacked fix until I can find something better:
so far, the only component that has need to make use of the "scale" function
for previewing is a JPanel with an overridden paint method, and the "super"
call that I had in that paint method was unnecessary, since the entire
surface is redrawn with my paint method. I took the super.paint() line out,
and now it works.
 
A

ak

Your revised example doesn't do anything towards the actual preview. If
you
add:
content.getContentPane().paint(g);
after the overridden paintComponent's super call, so that the component is
shown in the preview, you get the same error as before.
of course you become this error - because panel is child of content and you
have infinite painting loop here
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top