Re: adding a graphics2d object to a jpanel
- From: "Monique Y. Mudama" <spam@xxxxxxxxxxxxxxxx>
- Date: Mon, 30 Jan 2006 17:02:13 -0700
On 2006-01-30, 6e penned:
> is there a way to add a graphics2d object that alreasy exists to a
> jpanel?
>
> I have overridden jpanel as seen below, but cannot see the graphic
> object....
>
> any ideaS?
Either you know about a way to use a Graphics/Graphics2D object that
I've never seen, or you are trying to use a Graphics2D object in a way
that it was never intended to support.
Could you explain what you are trying to accomplish? Maybe there's a
better way to do it.
In the meantime, have you tried removing the paintComponent() method
entirely and just putting this in the constructor:
setBackground(Color.BLUE);
?
> public class JPanelGraphics2d extends JPanel{
>
> private static final long serialVersionUID = 001;
>
> Graphics2D m_g2d;
> private int maxUnitIncrement = 1;
>
> JPanelGraphics2d (Graphics2D g){
> m_g2d = g;
> setPreferredSize(new Dimension(450, 450));
> }
>
> public void paintComponent(Graphics g) {
> super.paintComponent(g);
>
> if (m_g2d != null){
> Graphics2D g2 = (Graphics2D)g;
>
> m_g2d.setBackground(Color.blue);
> g2 = m_g2d;
> System.out.println("always hit, but never shown on screen");
> }
> System.out.println("painting jpanelGraphics2d");
>
> }
> }
>
--
monique
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
.
- Follow-Ups:
- References:
- Prev by Date: Re: adding a graphics2d object to a jpanel
- Next by Date: Re: Drawing number tables
- Previous by thread: Re: adding a graphics2d object to a jpanel
- Next by thread: Re: adding a graphics2d object to a jpanel
- Index(es):