Results 1 to 8 of 8
- 11-07-2009, 09:07 PM #1
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
JFrame window doesnt change background color
Hai!
In the following code, this "game" still have same background color.
why?PHP Code:class gameFrame extends JFrame implements Runnable { // public void run(){ paintIt p = new paintIt(); add(p); } public gameFrame(){ //paintIt p = new paintIt(); //add(p); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(1000,1500); setTitle("Image test"); getContentPane().setBackground(Color.WHITE); setVisible(true); } }
Im using a loop to update the images showed on it but Idk.. The frame is never white, always grey..
How do I fix it?
-
what is a paintIt object? Is it a JPanel? Realize that this is being repeatedly added to the JFrame's contentPane BorderLayout.CENTER and will cover up the original contentPane (unless it is not opaque). So it probably doesn't matter what color you set the contentPane as I'll bet you'll never see it.
BTW, I'm not sure that I'd do my animation this way. I'd use one JPanel as an animation panel and then swap images in the same panel rather than creating and adding a bunch of components. Your way seems somewhat inefficient to me and may risk running out of memory.
- 11-07-2009, 09:20 PM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
How do you run the program? Why is your JFrame a Runnable?
- 11-07-2009, 09:21 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
-
- 11-07-2009, 09:23 PM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
Sry, but the runnable part was just leftovers..
Heres the loop thingy:
PHP Code:class MyTimerActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (!(Player.Y+Player.SizeY+2> 400)){ Player.CharVel[1] += 2; } else { Player.CharVel[0] = (Player.CharVel[0]/Player.Friction); } if (Player.Y+Player.SizeY> 400){ Player.CharVel[1] = -Player.CharVel[1]/2; Player.Y = 400-Player.SizeY; } Player.Y += Player.CharVel[1]; Player.X += Player.CharVel[0]+Player.CharWalk[0]; TestingArea.gf.repaint(); } }
- 11-07-2009, 09:36 PM #7
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
ahh, furbarable is right, the jpanel covers up the jframe
so If i did setBackground on jpanel then it shows.
Niceeee!!
THanks all!
-
glad you have it solved. Again, you probably don't want to continually add components here.
Similar Threads
-
How to change the default background color of a DISABLED JButton
By ryogananda in forum Java AppletsReplies: 4Last Post: 03-21-2009, 05:48 PM -
my code doesn't change background color
By javanoobita in forum New To JavaReplies: 5Last Post: 02-22-2009, 04:30 AM -
setting background color of JFrame form with NetBeans 6.1
By onefootswill in forum New To JavaReplies: 4Last Post: 08-12-2008, 07:02 AM -
JButton onClick change color background
By behrk2 in forum AWT / SwingReplies: 6Last Post: 07-09-2008, 04:54 PM -
window background color?
By javan00b in forum New To JavaReplies: 3Last Post: 01-29-2008, 10:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks