views:

285

answers:

3

Hi I have created a GUI for my program in Java, and I have used flowlayout (didnt have much luck with borderlayout), but with flowlayout if the user resizes the program, everything goes out of alignment, so i'm wondering is there anyway to stop the frame of the program from being resized? if so how?

Thank You

+4  A: 

JFrame::setResizable(false)

But this is bad practice; you need to investigate other layouts and potentially use multiple layouts to achieve you goals. See here.

See the api

geowa4
Thanks You, I would try other layouts but time is against me, but may I ask why it is bad practice?
It can be considered bad practice because windows are usually more usable when a user can resize them how they like. Lots of times though, it is not a big deal to have a fixed size form.
jjnguy
Ah I see, hopefully it shouldnt be a problem on mine as its a simple GUI, plus it will prevent the user from resizing it and then all the buttons and text fields going out of there positions.Thanks
I agree, George. You should always read the API documents. The Java docs are especially good, as are the tutorials.
Thomas Owens
+2  A: 

In order to stop a JFrame or JDialog all you need to do is call the method setResizable(false) on your frame or dialog.

You can do this in your constructor like:

public YourWindowNAme(){
    // stuff
    setResizable(false);
    // more stuff
}

or it can be called externaly like:

instanceOfYourWindow.setResizable(false);

Here is the API for the method.

jjnguy
Thank You that worked :D
@jjnguy: What make you edit your answer 6 months after?
OscarRyz
I received a random upvote and thus looked at this answer and noticed that I neglected to format some things as `code`
jjnguy
A: 

When you have better time this might interest you: http://www.netbeans.org/files/documents/4/475/matisse.html

It is the new layout manager arrived with Netbeans 6.

Thorbjørn Ravn Andersen
Thanks for that, defenetly will have a look after I have finished with this program.