| | |
help with setting background color!!!
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2006
Posts: 11
Reputation:
Solved Threads: 1
Hi Friends,
i made a window with a Panel and painted a text on it.
Now i want to set a background color for the panel but it does not reflect in the window..
i am posting the code here..
Please let me know if anything is wrong with the code!!
Thanks a lot!!
CODE..!!!
i made a window with a Panel and painted a text on it.
Now i want to set a background color for the panel but it does not reflect in the window..
i am posting the code here..
Please let me know if anything is wrong with the code!!
Thanks a lot!!
CODE..!!!
Java Syntax (Toggle Plain Text)
import javax.swing.*; import java.awt.*; import java.awt.event.*; class MyPan extends JPanel { public void paintComponent(Graphics g) { g.drawString("Hello India",50,50); } } class MyWin extends JFrame { MyWin() { MyPan Pan=new MyPan(); Pan.setBackground(Color.DARK_GRAY); Container Con=getContentPane(); Con.add(Pan); setTitle("Window With Panel"); setLocation(100,100); setSize(300,300); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); } } class WinPanel { public static void main(String arg[]) { MyWin w=new MyWin(); w.setVisible(true); } }
Last edited by cscgal; May 5th, 2006 at 9:59 pm.
The problem is in the paintComponent method of your MyPan class.
It should look like this:
:cheesy:
It should look like this:
Java Syntax (Toggle Plain Text)
public void paintComponent(Graphics g) { super.paintComponent(g); g.drawString("Hello India",50,50); }
:cheesy:
![]() |
Similar Threads
- iframe background color - pls help (HTML and CSS)
- how to place media page requests on background color (HTML and CSS)
- HTML 3.2 table background color (HTML and CSS)
- How Vb.NET Textbox background color change when TabStop come? (VB.NET)
- VS 2005 ListViews not holding background color (C#)
Other Threads in the Java Forum
- Previous Thread: Final GUI JFrame problem with actionlistner method
- Next Thread: Need help tweaking my program
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input int integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie nonstatic notdisplaying number online page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor






