🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #357

menu action vs repaint

#357
From: Hiroshi
Date: Mon, 05 Sep 2005 14:55
48 lines
2610 bytes
Q. Using Graphics object passed to paintComponent() draws only
the clip region for the object. So if paintComponent() is called
by a menu dropdown action, the region is set to the rect where
the dropdown covered, thus, using the passed object won't draw
outside the rect, right? To draw outside, Graphics for the
component (which is drawn into) is saved when the component is
created and used for the drawing. The problem this time is that
the clip region is not drawn while outside the region is drawn.
I need to draw a line in start(), below a menu, thus, to be
covered. How can I succeed in both (ie draw the 1st line at
start() and each and all lines after start(), covered or not?
Below I included the source to demonstrate my problem.
Thanks for reading ...

import java.awt.*;
import javax.swing.*;
public class tstMenu extends JApplet
{ mainPnl mp; Graphics mpG;
  public void init()
 { JMenuBar mb=new JMenuBar();
   JMenu mnu=new JMenu("Menu");
   mnu.add(new JMenuItem("Item"));
   mb.add(mnu);
   setJMenuBar(mb);
   mp=new mainPnl(this);
   getContentPane().add(mp,BorderLayout.CENTER);
 }
  public void start() {mpG=mp.getGraphics(); mp.repaint();}
}
class mainPnl extends JPanel
{ int calls;
  tstMenu tm;
  mainPnl(tstMenu tm0) {calls=0; tm=tm0;}
  public void paintComponent(Graphics g)
  {//g.setClip(0,0,300,300);
    super.paintComponent(g);
    if      (calls==1) //from start()'s repaint()
      g.drawString("paint1",10+10,5+12);
    //tm.mpG.drawString("paint1",10+10,5+12);
    else if (calls>1) {//from menu action
      for (int i=0;i<calls;i++)
        g.drawString("paint"+(i+1),10+(i+1)*10,5+(i+1)*12);
      //tm.mpG.drawString("paint"+(i+1),10+(i+1)*10,5+(i+1)*12);
    }                  //from constructor
    ++calls;
  }
}
Technical Details
Message-ID: <431c5c61$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.moat.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,76e66a81a2c6b8f1,start
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Hiroshi" <hiroshinakata@hotmail.com>
Sender: "Hiroshi" <hiroshinakata@hotmail.com>
Reply-To: "Hiroshi" <hiroshinakata@hotmail.com>
Subject: menu action vs repaint
Newsgroups: borland.public.jbuilder.java.swing
X-User-Info: 69.192.157.16     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <431c5c61$1@newsgroups.borland.com>
Date: 5 Sep 2005 07:55:29 -0700
X-Trace: newsgroups.borland.com 1125932129 207.105.83.66 (5 Sep 2005 07:55:29 -0700)
Lines: 48
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.moat.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail