On Mon, Feb 09, 2004 at 01:31:40AM -0700, Andrei Kouznetsov wrote:
 > >>no need to call drawingPanel.getGraphics() in drawMap() because you
 > >have
 > >>alredy Graphics from paintComponent.
 > >
 > >>drawingPanel = new JPanel(){
 > >>            public void paintComponent(Graphics g){
 > >>                super.paintComponent(g);
 > >>                drawMap((Graphics2D)g);
 > >>            }
 > >>        };
 > >
 > >>private void drawMap(Graphics2D g2){
 > >>g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALU
 > >E
 > >>ANTIALIAS_ON);
 > >>       // custom paint code
 > >>  }
 > >
 > >If I do this, nothing is drawn! It shouldn't have any effect on
 > >repainting overlapping areas, which is the problem I'm having.  I'm just
 > >creating an extra Graphics object.

  Note that by calling component.getGraphics() you were not just
  creating an extra Graphics object, but a graphics context to render
  to the screen directly, bypassing the double-buffering swing
  painting mechanism. In a well-behaved swing application this should
  never be done for the exact reasons you're experiencing.

  Andrei's suggestion is the correct way to do it.

  Thank you,
    Dmitri

 >
 > then use Graphics#create():
 >
 > drawingPanel = new JPanel(){
 >             public void paintComponent(Graphics g){
 >                 super.paintComponent(g);
 >                 drawMap((Graphics2D)g.create());
 >                 //or
 >                 //drawMap((Graphics2D)g.create(x, y, w, h));
 >             }
 >         };
 >
 > ===========================================================================
 > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
 > of the message "signoff JAVA2D-INTEREST".  For general help, send email to
 > [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to