Article View: borland.public.jbuilder.java.swing
Article #9535Why does RepaintManager.getOffScreenBuffer return a null when I give it a JPanel?
From: John Hines
Date: Thu, 09 Mar 2000 00:00
Date: Thu, 09 Mar 2000 00:00
84 lines
3951 bytes
3951 bytes
This is a modification of an earlier post now that I understand the problem
a little better.
In JDK 1.2.2, I am trying to convert an applet that displays a picture in an
HTML page to a servlet that downloads the picture to the HTML page. In my
inherited code, the picture is built by placing a bunch of gifs in a
JScrollPane that is added to an instance of a subclass of JPanel.
The code shown below (which uses a brute force created Image) works fine.
At least, it shows the expected image. And, the size of boundary appears to
be about the right size. Finally, when I call the program with different
arguments for the proces, the values of Dimension.width and Dimension.height
change in reasonable ways.
However, when I try to get an image from my code using the call
img = manager.getOffscreenBuffer(diagramManager, dim.width , dim.height );
img is null. So, nothing works.
I'm sure I'm doing something stupid. But, what? I've tried to do repaints
and ... on the panel but nothing I have done has changed the output of
getOffscreenBuffer! It's always null!
John Hines
RepaintManager manager = RepaintManager.currentManager(null);
if (manager == null)
throw new Exception("null manager in createProcessDiagram in
ProcessDiagramViewerServlet");
manager.setDoubleBufferingEnabled(true);
DiagramManager diagramManager = null ; //Derived from JPanel
BufferedImage bufferedImage = null ;
if (tempProcessList != null) {
theProcess = (Enactable)tempProcessList.elementAt(0);
try {
theProcess.initContents(theSession); //build a picture of the
contents
//--------------------------------------------------------------------------
-----------
// diagram manager is non-null here!
diagramManager = new DiagramManager(theProcess, this); //create
image
// I tried doing paint and repaint and ..., none of which made a
difference
//--------------------------------------------------------------------------
-----------
Dimension dim = diagramManager.getPreferredSize();
Image img =getImage(getImageUrl( "process.gif"));
//--------------------------------------------------------------------------
------------
//the next line always returns a null even though dim.width and
dim.height are not null
//img = manager.getOffscreenBuffer(diagramManager, dim.width ,
dim.height );
//the previous line always returns a null even though dim.width and
dim.height are not null
//--------------------------------------------------------------------------
-------------
if (img == null)
throw new Exception("null image in createProcessDiagram in
ProcessDiagramViewerServlet");
bufferedImage = new BufferedImage(dim.width, dim.height,
BufferedImage.TYPE_INT_RGB);
Graphics bufferedGraphics = bufferedImage.getGraphics();
bufferedGraphics.drawImage(img, 0, 0, null) ;
}
catch (WFException e) {
System.out.println("WFException: initContents on non-process");
throw new ServletException("Unable to create image in
createProcessImage");
}
catch (Exception e) {
System.out.println("Exception: " + e);
throw new ServletException("Unable to create image in
createProcessImage");
}
}
Technical Details
Message-ID:
<8a95v8$gmc3@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,eda4df71cc5cc01d,start X-Google-Attributes: gid111d45,public From: "John Hines" <jrhines@onramp.net> Subject: Why does RepaintManager.getOffScreenBuffer return a null when I give it a JPanel? Date: 2000/03/09 Message-ID: <8a95v8$gmc3@bornews.borland.com> X-Deja-AN: 595342191 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.swing