Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By doWhile

Thread: Drawing on a Panel

  1. #1
    jonbink16 is offline Member
    Join Date
    Jun 2012
    Posts
    1
    Rep Power
    0

    Default Drawing on a Panel

    The drawing of an Image on a panel wont show up until I minimize and then re-open the JFrame. Also, the mousePressed and mouseReleased functions wont work until I resize the JFrame. Is there anything that I need to add to the code to make me not have to do this?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Drawing on a Panel

    You should provide context in the form of a SSCCE - concentrating on one thing at a time. I can render a guess that you are adding components after the JFrame is visible, but can only guess given the amount of information.
    Fubarable likes this.

  3. #3
    mrguy is offline Member
    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0

    Default Re: Drawing on a Panel

    I think this will work. When the window is ready then it does the following code.


    Java Code:
    panel.addWindowListener(new WindowAdapter() {
    	public void windowActivated(WindowEvent e) {
    		repaint();
    	}
    });
    I hope this works.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Drawing on a Panel

    Quote Originally Posted by mrguy View Post
    I think this will work. When the window is ready then it does the following code.


    Java Code:
    panel.addWindowListener(new WindowAdapter() {
    	public void windowActivated(WindowEvent e) {
    		repaint();
    	}
    });
    I hope this works.
    That won't come close to solving the original poster's problem, sorry. He possibly is not calling repaint() inside of his MouseListener, but til he posts his code, who knows.

  5. #5
    mrguy is offline Member
    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0

    Default Re: Drawing on a Panel

    I have had this problem before and I believe this code does work. though it may not be repaint() that he needs to call. But yes for anyone who had not had this problem before would need context.

Similar Threads

  1. panel on a panel not visible
    By warchieflll in forum Advanced Java
    Replies: 2
    Last Post: 01-29-2011, 09:29 PM
  2. Add panel to parent panel
    By LovJava in forum AWT / Swing
    Replies: 10
    Last Post: 09-02-2010, 09:43 PM
  3. Panel in a panel?
    By pahiker in forum AWT / Swing
    Replies: 1
    Last Post: 07-05-2010, 12:42 PM
  4. Adding a panel to a panel
    By rclausing in forum New To Java
    Replies: 7
    Last Post: 02-02-2010, 06:56 AM
  5. Undoable Drawing Panel
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 08:52 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
  •