Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Whew. Paint Question.  (Read 1188 times)
0 Members and 2 Guests are viewing this topic.
Offline bh94704

JGO n00b
*

Posts: 17


AxAy(x=y)


« on: 2003-11-12 22:07:46 »

1.4.2, WinXP, Netbeans

Hi all,

I just came back to my old project after 3-4 months of lifting heavy objects for money. I think I may have forgotten how to program, so I apologize if this is a stupid question.

I am trying to create a Swing GUI where the ContentPane has a BorderLayout. The graphics and action occur in the center area, which has no child; I draw to the ContentPane directly. Options and user input are on a JTabbedPane in the South, and scoring and time limit are displayed on a JPanel in the North.

I want the graphics drawn right on the contentPane to wrap snugly around the three tabs on the TabbedPane (they are on top of it), as well as around the TP itself. I figure the best way to do this is, draw the graphics to my buffer, then paint the TP onto the buffer, then flip. This is my code: (imageBuffer is just a blank BufferedImage)

backBuffer = ((Graphics2D) imageBuffer.getGraphics());
gameMap.drawIsometricMap(backBuffer);
managementTabbedPane.paint(backBuffer);
getContentPane().drawImage(backBuffer, 0, 0, this);

What ends up happening is, the TP paints once where it belongs, in the South, (and the TP functions normally), then it repaints about at about (0, 4) for the remainder of the program execution. The graphics overlap the real TP (because it isn't repainting where it should), and the empty shell of a TP paints perfectly over the graphics, in the wrong place.

Does anyone know why this is happening? Basically, it seems to me that the TP contains the wrong information about exactly where it belongs at any given time. I tried setting its location absolutely (with setLocation(x, y)), didn't work. Perhaps I'm on the wrong track to acheive this effect in the first place? Any help is much appreciated. Thanks,

Bret
Offline bh94704

JGO n00b
*

Posts: 17


AxAy(x=y)


« Reply #1 on: 2003-11-14 17:39:10 »

Well, I figured it out. Maybe folks will be interested in the answer. Actually, I haven't tried it yet (not at home), but it's too spot-on to ignore. According to the API of Component.paint(Graphics g),

Quote
The clip rectangle in the Graphics parameter is set to the area which needs to be painted.


Funny that they don't spell this out in any of Component's subclasses.  Tongue
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.058 seconds with 17 queries.