Results 1 to 4 of 4
  1. #1
    slum is offline Member
    Join Date
    Sep 2014
    Posts
    4
    Rep Power
    0

    Default Resize paintComponents

    Hi. I have created a small program with methods of the Graphics class. I want to resize the frame and make it fit the screen, but after trying various layout managers, have come to the conclusion that by setting the sizes of the various shapes specifically in the paintComponent method, I can't resize. Is it possible to resize a frame with its paintComponent methods? Maybe I'm just not using the layout managers correctly but the Graphics just wont resize. I have tried setting the weights when I used GridBagLayout.. not working. I thought maybe there is a way to set the frame or panel to take the Graphics and then resize the panel. That doesn't work either.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Resize paintComponents

    If you're using LayoutManagers, never try to resize any managed Component yourself; let the LayoutManager handle that. Of course you can resize any 'top level' component (such as a JFrame) yourself.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    slum is offline Member
    Join Date
    Sep 2014
    Posts
    4
    Rep Power
    0

    Default Re: Resize paintComponents

    Thanks. I can resize the frame but stuff I draw is drawn in the sizes which I have specified. I'm doubtful that the actual stuff I've painted can be resized. Just say the word and I'll paste the code here..

    So I think I should specify the width and height of my drawings to be a variable?
    Last edited by slum; 09-08-2014 at 10:59 AM.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Resize paintComponents

    Quote Originally Posted by slum View Post
    Thanks. I can resize the frame but stuff I draw is drawn in the sizes which I have specified. I'm doubtful that the actual stuff I've painted can be resized. Just say the word and I'll paste the code here..

    So I think I should specify the width and height of my drawings to be a variable?
    Yep, don't specify any size at all; let the LayoutManager do that. Your paintComponent( ... ) method can always find its current size by caling getWidth() and getHeight().

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. paintComponents(g) instead of paintComponents(g)
    By skiabox in forum New To Java
    Replies: 4
    Last Post: 01-10-2012, 11:53 PM
  2. Why is java paintComponents() not working?
    By jujubinaj in forum AWT / Swing
    Replies: 10
    Last Post: 12-20-2010, 02:26 PM
  3. paintComponent vs paintComponents
    By alacn in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 04:33 AM
  4. can't resize my JLabel
    By gib65 in forum AWT / Swing
    Replies: 10
    Last Post: 06-25-2010, 06:30 AM
  5. how to resize an image
    By marodia in forum AWT / Swing
    Replies: 2
    Last Post: 08-21-2009, 05:10 AM

Posting Permissions

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