Results 1 to 2 of 2
Thread: How do I Update JFrame Size
- 01-23-2012, 11:31 PM #1
Member
- Join Date
- Jan 2012
- Location
- Texas
- Posts
- 1
- Rep Power
- 0
How do I Update JFrame Size
Ok so lets say i have a simple JFrame and i do:
public int framewidth = 720;
public int frameheight = 480;
JFrame frame = new JFrame();
frame.setSize(framewidth, frameheight);
And then on another page of code i change those int's:
ClassName frameclass = new ClassName();
frameclass.framewidth = 1920;
frameclass.frameheight = 1080;
After that i get stuck because the JFrame size dosn't refresh. It stays the original 720, 480. The second class is a action listener to a JButton which changes the variables. If it is possible to refresh it somehow i would really appriciate some help. I also have the same problems with JLables but that isnt such a big deal. If any one can help PLEASE!!!
-
Re: How do I Update JFrame Size
Your problem is common for those starting out in Java. When you use primitives to set some property, changing the primitives later has no effect on the properties. For instance, say a JFrame has internal variables that hold its size (or better its preferred size), and by calling frame.setSize(framewidth, frameheight) in the JFrame's internal code you would probably be setting those variables, something like:
So when you call this method, the values held by your ints are passed into this method and used to set the JFrame's internal variables.Java Code:public void setSize(int width, int height) { this.internalWidth = width; this.internalHeight = height; }
Now if later on in your program you change your framewidth and frameheight variables, this will have no effect on the JFrame's internal variables since the two sets of variables are not linked in any way. If you need to reset a JFrame's size, you'll have to call the setSize(...) method all over again in order to change the JFrame's internal properties.
Having said that, it's usually not a good idea to set a component's size but rather to let the layout managers do this for you.
Similar Threads
-
JFrame Size
By newbie123 in forum AWT / SwingReplies: 7Last Post: 09-08-2011, 05:30 PM -
How do I update a JFrame?
By soulmed in forum New To JavaReplies: 4Last Post: 04-20-2011, 08:45 PM -
JFrame 's components size and location problem
By petrosgraf in forum Threads and SynchronizationReplies: 5Last Post: 04-18-2009, 02:24 AM -
Image size in a JFrame
By nickbeacroft in forum AWT / SwingReplies: 2Last Post: 06-26-2008, 04:08 PM -
Listener for JFrame size change
By Thez in forum AWT / SwingReplies: 10Last Post: 02-14-2008, 03:10 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks