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

Thread: JFrame cannot paint?

  1. #1
    pandaman0212 is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default JFrame cannot paint?

    This problem is kinda weird.
    I made a class that extended JFrame, but whenever I try to override with its paint method, all it show is a JFrame with a transparent background that shows whatever is on my screen. If I don't override the paint method, it will show up as a normal JFrame with nothing inside, how do i solve this problem?

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

    Default

    Simple: don't override paint for a JFrame. There's rarely ever a reason you want to do this.

    If you want to paint inside of a JFrame, do this in a JPanel's paintComponent method override, and place that JPanel in the JFrame's contentPane. Be sure that you don't stop the flow of code in this method with a Thread.sleep or while (true) construct, else you'll freeze your app.

  3. #3
    pandaman0212 is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    I know there are other method to deal with it, but i am just curious why it happen. Thanks anyways

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

    Default

    Quote Originally Posted by pandaman0212 View Post
    I know there are other method to deal with it, but i am just curious why it happen. Thanks anyways
    How can we guess the reason without code?

  5. #5
    pandaman0212 is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    well, cuz it happen everytime the paint method is replaced

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

    Default

    Quote Originally Posted by pandaman0212 View Post
    well, cuz it happen everytime the paint method is replaced
    So you're doing something bad in the code, like not calling the super paint method, but if you won't show us the method, I'm not in much a mood to guess.

  7. #7
    cssumit is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default Re: JFrame cannot paint?

    Quote Originally Posted by Fubarable View Post
    So you're doing something bad in the code, like not calling the super paint method, but if you won't show us the method, I'm not in much a mood to guess.
    bt it happens only in windows . In linux its not.. why??

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

    Default Re: JFrame cannot paint?

    Please don't hijack someone else's post, especially one that's over two years old, and especially with a seemingly unrelated question. Thread locked.
    DarrylBurke likes this.

Similar Threads

  1. Replies: 5
    Last Post: 06-14-2010, 06:10 PM
  2. Replies: 6
    Last Post: 04-12-2010, 11:33 AM
  3. how to add more than one paint method
    By gautham in forum Java 2D
    Replies: 2
    Last Post: 04-06-2010, 07:07 AM
  4. Passing data from one JFrame to another JFrame
    By tarami in forum New To Java
    Replies: 3
    Last Post: 08-06-2009, 05:44 PM
  5. Replies: 4
    Last Post: 04-22-2009, 11:02 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
  •