Results 1 to 7 of 7
Thread: Problems with setBackground()
- 03-06-2010, 10:02 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 3
- Rep Power
- 0
Problems with setBackground()
What's up guys!
It is my very first thread in here. I am a beginner in Java Programming.
The program should display a FullScreen Window with a setBackground Color
and some Message.
at Line 13 in orange.java: I set the Background to PINK.
However the screen remains BLACK. The Foreground is displayed correctly.
Please help me to understand the Problem, why I can not set the Background color.
Two files are attached.
- 03-06-2010, 10:57 PM #2
Member
- Join Date
- Nov 2009
- Posts
- 54
- Rep Power
- 0
I think the problem is that is your class orange, in the paint method, you don't call super.paint( g ); . If you place this statement on top of your paint method, the background will become pink.
Hannes
- 03-06-2010, 11:29 PM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,144
- Rep Power
- 5
To increase your chances of getting help you should create a Short, Self Contained, Compilable and Executable, Example Program (SSCCE), that demonstrates the incorrect behaviour.It is my very first thread in here.
- 03-07-2010, 10:44 AM #4
Member
- Join Date
- Mar 2010
- Posts
- 3
- Rep Power
- 0
- 03-07-2010, 11:30 AM #5
Member
- Join Date
- Nov 2009
- Posts
- 54
- Rep Power
- 0
have a look at Painting in AWT and Swing. There you can find a explanation of how the painting in awt and swing works, and what methods you should override.
Hannes
- 03-07-2010, 04:16 PM #6
Member
- Join Date
- Mar 2010
- Posts
- 3
- Rep Power
- 0
I got my Problem solved by a user from another forum!
One should use ContentPane from JPanel.:) Still have to study that stuff carefully.
Java Code:public void run(DisplayMode dm){ getContentPane().setBackground(Color.BLUE); setForeground(Color.RED); ... } public void paint(Graphics g){ super.paint(g); // Der super-Aufruf sollte bei überschriebenen paint*-Methoden immer die erste Zeile sein! if(g instanceof Graphics2D){ ... }
- 03-07-2010, 04:59 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,423
- Blog Entries
- 7
- Rep Power
- 17
Last edited by JosAH; 03-07-2010 at 05:10 PM.
Similar Threads
-
JButton.setBackground() Problem
By ellias2007 in forum AWT / SwingReplies: 2Last Post: 02-24-2010, 09:49 PM -
Gui problems
By bulldog in forum Advanced JavaReplies: 1Last Post: 12-11-2009, 12:35 PM -
having problems
By pinkdiamondgail in forum New To JavaReplies: 6Last Post: 02-06-2009, 11:35 PM -
many to many problems
By cecily in forum JDBCReplies: 1Last Post: 08-02-2007, 05:51 PM -
problems with JPA
By Ed in forum New To JavaReplies: 2Last Post: 07-04-2007, 05:34 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks