| | |
help with setting background color!!!
![]() |
•
•
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 |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop eclipse error fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie number objects online oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time title tree tutorial-sample ubuntu update windows working






