i have a question about JFrame. is there anyway to set the size of frame as automatic depending about the values in the frame.so if the values is a lot more than what is expected that frame adjust it self it fit all the data ?

A frame will size itself according to the components contained within. Whether that answers your question about the "data" remains to be seen (since I, obviously, have no idea how your displaying that "data"). But, as a hunch, no, you do not have to use setSize() on a JFrame.

in fact the setSize method usually has no effect whatsoever as the frame will automatically resize itself according to the sizes of the components it contains.

well i am using JtxtArea to display my data ....but if the data in the JtxtArea more than what the frame size can hold the frame does not automatically fix its size...

Set the proper component size for the JTextArea.

JTextArea(String text, int rows, int columns)
// or
setColumns(int columns)
setRows(int rows)

Edit: And, you will probably want to place it in a JScrollPane.

in fact the setSize method usually has no effect whatsoever as the frame will automatically resize itself according to the sizes of the components it contains.

Actually, if call setSize after pack, then call validate before calling setVisible, it works just fine (as it is pack that "resizes" the JFrame).

Not that I find it necessary to do so, but some people want to. ;-)

maybe, but that doesn't resize anything on the visible frame, which is what's usually meant by such questions :)
It's also unreliable, depends on what component you're working with and how it's placed.

Essentially, one should not depend on hardwiring component sizes.

And indeed, wrap that JTextArea with a JScrollPane.

This article has been dead for over six months. Start a new discussion instead.