Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
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 2006 times)
0 Members and 1 Guest are viewing this topic.
Offline bh94704

Senior Newbie


« 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());
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,

Offline bh94704

Senior Newbie


« 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),

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.

theagentd (111 views)
2017-02-18 13:42:33

theagentd (115 views)
2017-02-18 13:35:16

h.pernpeintner (1279 views)
2017-01-24 22:39:11

h.pernpeintner (1267 views)
2017-01-24 22:38:32

Galdo (1827 views)
2017-01-12 13:44:09

Archive (1931 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2469 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2301 views)
2016-12-15 21:50:57

Lunch (2380 views)
2016-12-06 16:01:40

ral0r2 (2156 views)
2016-11-23 16:08:26
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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‑
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!