InternalError "cannot nest locks"

Discussion in 'Java' started by Elrod, Jun 11, 2004.

  1. Elrod

    Elrod Guest

    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(
    at sun.java2d.pipe.DrawImage.transformImage(
    at sun.java2d.pipe.DrawImage.copyImage(
    at sun.java2d.pipe.DrawImage.copyImage(
    at sun.java2d.pipe.ValidatePipe.copyImage(
    at sun.java2d.SunGraphics2D.drawImage(
    at sun.java2d.SunGraphics2D.drawImage(
    at javax.swing.JComponent.paintWithOffscreenBuffer(
    at javax.swing.JComponent.paintDoubleBuffered(
    at javax.swing.JComponent.paint(
    at ipos3.PreviewTest$1.paint(
    at javax.swing.JComponent.paintChildren(
    at javax.swing.JComponent.paint(
    at javax.swing.JLayeredPane.paint(
    at javax.swing.JComponent.paintWithOffscreenBuffer(
    at javax.swing.JComponent.paintDoubleBuffered(
    at javax.swing.JComponent._paintImmediately(
    at javax.swing.JComponent.paintImmediately(
    at javax.swing.RepaintManager.paintDirtyRegions(
    at javax.swing.SystemEventQueueUtilities$
    at java.awt.event.InvocationEvent.dispatch(
    at java.awt.EventQueue.dispatchEvent(
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(
    at java.awt.EventDispatchThread.pumpEvents(
    at java.awt.EventDispatchThread.pumpEvents(

    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
    JButton btnPreview;
    JDesktopPane desktop;
    JInternalFrame content;
    public PreviewTest() {
    getContentPane().add(desktop = new
    content = new JInternalFrame("Testing");
    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" }
    getContentPane().add(btnPreview = new

    public void actionPerformed(java.awt.event.ActionEvent e) {
    JInternalFrame preview = new JInternalFrame("Preview") {
    public void paint(Graphics g) {
    // The following line is what's causing the problem
    // comment it out, and the preview button works

    public static void main(String[] args) {
    new PreviewTest().show();
    Elrod, Jun 11, 2004
    1. Advertisements

  2. Elrod

    ak Guest

    public void actionPerformed(java.awt.event.ActionEvent e) {
    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);

    JInternalFrame preview = new JInternalFrame("Preview");

    preview.setSize(350, 350);
    desktop.add(preview, 1);;
    ak, Jun 12, 2004
    1. Advertisements

  3. Elrod

    Elrod Guest

    // added by Elrod
    // end alteration
    Your revised example doesn't do anything towards the actual preview. If you
    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.
    Elrod, Jun 12, 2004
  4. Elrod

    ak Guest

    Your revised example doesn't do anything towards the actual preview. If
    of course you become this error - because panel is child of content and you
    have infinite painting loop here
    ak, Jun 13, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.