Painting on a JPanel - HELP!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Graham Norman

    Painting on a JPanel - HELP!

    I have overridden the following method with:

    protected void paintComponent( Graphics g)
    {
    super.paintComp onent(g);
    Graphics2D g2 = (Graphics2D)g;
    JigsawPiece tmp;

    while (hasNext())
    {
    tmp = nextJigsawPiece ();
    g2.drawImage(tm p.getPartialIma ge(), tmp.getRelative XCoord(),
    tmp.getRelative YCoord(), this);
    }
    }

    When I load my program, nothing appears. I go to resize the window and the
    image appears, I move or resize the window again and it dissappears.

    Pleeease help me,
    Graham.


  • SPG

    #2
    Re: Painting on a JPanel - HELP!

    Does it help to put this code in the paint() method instead?
    I have had trouble with re-painting using swing before, and found that
    putting it all inpaint() helped.

    Steve
    "Graham Norman" <[email protected] k> wrote in message
    news:botacb$rmq [email protected] rnet.com...[color=blue]
    > I have overridden the following method with:
    >
    > protected void paintComponent( Graphics g)
    > {
    > super.paintComp onent(g);
    > Graphics2D g2 = (Graphics2D)g;
    > JigsawPiece tmp;
    >
    > while (hasNext())
    > {
    > tmp = nextJigsawPiece ();
    > g2.drawImage(tm p.getPartialIma ge(), tmp.getRelative XCoord(),
    > tmp.getRelative YCoord(), this);
    > }
    > }
    >
    > When I load my program, nothing appears. I go to resize the window and the
    > image appears, I move or resize the window again and it dissappears.
    >
    > Pleeease help me,
    > Graham.
    >
    >[/color]


    Comment

    • Bryan Boone

      #3
      Re: Painting on a JPanel - HELP!

      Graham Norman wrote:
      [color=blue]
      > I have overridden the following method with:
      >
      > protected void paintComponent( Graphics g)
      > {
      > super.paintComp onent(g);
      > Graphics2D g2 = (Graphics2D)g;
      > JigsawPiece tmp;
      >
      > while (hasNext())
      > {
      > tmp = nextJigsawPiece ();
      > g2.drawImage(tm p.getPartialIma ge(), tmp.getRelative XCoord(),
      > tmp.getRelative YCoord(), this);
      > }
      > }
      >
      > When I load my program, nothing appears. I go to resize the window and the
      > image appears, I move or resize the window again and it dissappears.
      >
      > Pleeease help me,
      > Graham.
      >
      >[/color]
      You need to override getPreferredSiz e() to return the preferred size of
      the JPanel.

      Comment

      Working...