Results 1 to 10 of 10
  1. #1
    cwbr is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Some parts of JFrame off screen

    I have a JFrame with an Image drawn onto it. The JFrame is 400x300, as is the Image. Unfortunately, some of the Image is not being drawn to the screen. I'm pretty sure it's in the right place as far as the JFrame is concerned, but the window border, and the title bar are hiding some of the Image. How do I get the contents of the window to be 400x300, rather than the window itself?
    Is it just trial and error, or is there a better way?
    Thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Some parts of JFrame off screen

    Can't you just set the size of the component drawing the image?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Some parts of JFrame off screen

    Or just use a JLabel with an ImageIcon added to the CENTER of the JFrame's default BorderLayout, and call pack()

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    cwbr is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Re: Some parts of JFrame off screen

    The component drawing the image? I don't understand. I have JFrame.setSize(400, 300), and then I use Graphics2D.drawImage to draw an image to it, but the border of the window that comes up hides some of the image.

    I'm sure there must be a better way of doing it than having to put in a JLabel, but if it comes to that I'll try it.

    Here's how it comes out if I make the JFrame 400x300:

    Some parts of JFrame off screen-game.png

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Some parts of JFrame off screen

    The first thing you're doing wrong is performing custom painting in a top level window.

    If for whatever crazy reason you're not comfortable with a JLabel/ImageIcon, then learn how to do custom painting correctly:
    Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: Some parts of JFrame off screen

    The JFrame is 400x300, as is the Image.
    Well, you can't make the frame the same size as the image because the frame also has a titlebar and borders to worry about.

    I'm sure there must be a better way of doing it than having to put in a JLabel,
    That IS the better way.

    There is no need to reinvent the wheel by doing the custom painting yourself.
    Last edited by camickr; 01-27-2012 at 05:18 AM.

  7. #7
    cwbr is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Re: Some parts of JFrame off screen

    I've solved this now...but I'm not sure if you can delete threads once they're done.
    Last edited by cwbr; 01-29-2012 at 02:02 AM. Reason: Solved own problem

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Some parts of JFrame off screen

    Quote Originally Posted by cwbr View Post
    I've solved this now...but I'm not sure if you can delete threads once they're done.
    Why would you want to delete it? Part of the purpose behind these forums is so that other people with similar problems in the future can learn from the answers you received. With that in mind, you might consider posting what you did to solve your problem.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    cwbr is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Re: Some parts of JFrame off screen

    I'm not sure it's that easy to find a solution by looking through old threads, but in case someone does the solution provided by DarrylBurke (i.e. custom painting) worked nicely.

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Some parts of JFrame off screen

    Quote Originally Posted by cwbr View Post
    I'm not sure it's that easy to find a solution by looking through old threads, but in case someone does the solution provided by DarrylBurke (i.e. custom painting) worked nicely.
    It is if the original posters provide meaningful titles and detailed questions. Who knows, coming across this thread might make somebody's day a year from now (hi, people of the future!).
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 0
    Last Post: 09-12-2011, 01:06 PM
  2. several threads for different parts
    By Itun in forum AWT / Swing
    Replies: 2
    Last Post: 03-20-2011, 11:18 PM
  3. need help with few parts in java program please!
    By fezman1337 in forum JCreator
    Replies: 1
    Last Post: 11-22-2010, 05:26 PM
  4. Replies: 1
    Last Post: 04-26-2010, 01:02 PM
  5. JFrame at Center Screen
    By hiranya in forum AWT / Swing
    Replies: 8
    Last Post: 02-11-2010, 04:29 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
  •