Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Whew. Paint Question.  (Read 1584 times)
0 Members and 1 Guest are viewing this topic.
Offline bh94704

Senior Newbie




AxAy(x=y)


« Posted 2003-11-13 03: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

Senior Newbie




AxAy(x=y)


« Reply #1 - Posted 2003-11-14 22: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (46 views)
2014-10-17 03:59:02

Norakomi (37 views)
2014-10-16 15:22:06

Norakomi (28 views)
2014-10-16 15:20:20

lcass (32 views)
2014-10-15 16:18:58

TehJavaDev (62 views)
2014-10-14 00:39:48

TehJavaDev (62 views)
2014-10-14 00:35:47

TehJavaDev (52 views)
2014-10-14 00:32:37

BurntPizza (70 views)
2014-10-11 23:24:42

BurntPizza (40 views)
2014-10-11 23:10:45

BurntPizza (82 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!