Results 1 to 6 of 6
  1. #1
    Fuzzier is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default 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.

    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){
    		
    	}
    	
    }
    When I delete the paint methode, the components are presenting fine.
    What is the problem?

    :) sorry for the bad english

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,574
    Rep Power
    23

    Default

    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);

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    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.

  4. #4
    Fuzzier is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    @Norm:
    The method there just to show the problem
    @camickr:
    :\ So how do I paint things in SWING without the paint method?

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

  6. #6
    Fuzzier is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

Similar Threads

  1. painting problem
    By hannes in forum New To Java
    Replies: 3
    Last Post: 01-17-2010, 11:44 AM
  2. Replies: 12
    Last Post: 10-09-2009, 06:26 AM
  3. Jpanel painting problem
    By kcakir in forum AWT / Swing
    Replies: 3
    Last Post: 04-15-2009, 10:21 PM
  4. JApplet Problem
    By tanmoy.b81 in forum AWT / Swing
    Replies: 2
    Last Post: 07-28-2008, 06:56 AM
  5. Another problem in JApplet :S
    By juju in forum Java Applets
    Replies: 2
    Last Post: 12-30-2007, 07:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •