Results 1 to 6 of 6
Thread: Problem with JApplet painting
- 07-29-2010, 01:08 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 5
- Rep Power
- 0
Problem with JApplet painting
I have an applet with some few lightweight(Swing) components on it.
When I run it, the components dose not appear until I pointing on them with the mouse.
When I delete the paint methode, the components are presenting fine.Java Code:public class test extends JApplet implements Runnable{ JButton btn; JTextField txt; JLabel lbl; public void init(){ this.setSize(300, 300); this.setLayout(new FlowLayout(1,0,0)); btn = new JButton(""); btn.setPreferredSize(new Dimension(50,10)); txt = new JTextField(""); txt.setPreferredSize(new Dimension(50,10)); lbl = new JLabel("Test"); lbl.setPreferredSize(new Dimension(50,10)); add(btn); add(txt); add(lbl); } public void run(){ } public void paint(Graphics g){ } }
What is the problem?
:) sorry for the bad english
- 07-29-2010, 02:57 PM #2
Why do you want to have an empty paint method that overrides the class's paint method?
If you want to override it you need to provide code to do what the paint method is supposed to do. If you want to extend what the JApplet's paint() method does, add the following line to your paint method:
super.paint(g);
- 07-29-2010, 04:05 PM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
You should NEVER override the paint() method of a JApplet (or JFrame or JDialog). That is an old AWT trick and should NOT be used with Swing.
- 07-29-2010, 04:50 PM #4
Member
- Join Date
- Oct 2009
- Posts
- 5
- Rep Power
- 0
@Norm:
The method there just to show the problem
@camickr:
:\ So how do I paint things in SWING without the paint method?
- 07-29-2010, 06:20 PM #5
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
- 07-29-2010, 08:54 PM #6
Member
- Join Date
- Oct 2009
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
painting problem
By hannes in forum New To JavaReplies: 3Last Post: 01-17-2010, 11:44 AM -
Problem with painting the contents of a file on a JTextArea
By Willi in forum AWT / SwingReplies: 12Last Post: 10-09-2009, 06:26 AM -
Jpanel painting problem
By kcakir in forum AWT / SwingReplies: 3Last Post: 04-15-2009, 10:21 PM -
JApplet Problem
By tanmoy.b81 in forum AWT / SwingReplies: 2Last Post: 07-28-2008, 06:56 AM -
Another problem in JApplet :S
By juju in forum Java AppletsReplies: 2Last Post: 12-30-2007, 07:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks