Results 1 to 10 of 10
Thread: Some parts of JFrame off screen
- 01-26-2012, 04:36 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 10
- Rep Power
- 0
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
- 01-26-2012, 04:59 PM #2
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!
- 01-26-2012, 06:54 PM #3
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()
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-27-2012, 04:49 AM #4
Member
- Join Date
- Nov 2011
- Posts
- 10
- Rep Power
- 0
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:
- 01-27-2012, 05:15 AM #5
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)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-27-2012, 05:16 AM #6
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: Some parts of JFrame off screen
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.The JFrame is 400x300, as is the Image.
That IS the better way.I'm sure there must be a better way of doing it than having to put in a JLabel,
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.
- 01-28-2012, 03:04 PM #7
Member
- Join Date
- Nov 2011
- Posts
- 10
- Rep Power
- 0
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
- 01-30-2012, 02:43 PM #8
Re: Some parts of JFrame off screen
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-30-2012, 04:14 PM #9
Member
- Join Date
- Nov 2011
- Posts
- 10
- Rep Power
- 0
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.
- 01-30-2012, 05:40 PM #10
Re: Some parts of JFrame off screen
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
-
Public API for Custom XML Parts & Custom Parts, Graphics Rendering
By sherazam in forum Java SoftwareReplies: 0Last Post: 09-12-2011, 01:06 PM -
several threads for different parts
By Itun in forum AWT / SwingReplies: 2Last Post: 03-20-2011, 11:18 PM -
need help with few parts in java program please!
By fezman1337 in forum JCreatorReplies: 1Last Post: 11-22-2010, 05:26 PM -
unable to clear text Field in Multi Screen JFrame GUI Application
By harshalforu in forum AWT / SwingReplies: 1Last Post: 04-26-2010, 01:02 PM -
JFrame at Center Screen
By hiranya in forum AWT / SwingReplies: 8Last Post: 02-11-2010, 04:29 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks