jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes visualising the contents of the frame without resizing[urgent] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "visualising the contents of the frame without resizing[urgent]" Watch "visualising the contents of the frame without resizing[urgent]" New topic

visualising the contents of the frame without resizing[urgent]

netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
When a JFrame is created it has to be resized to view the components added to it.Is there any way to highlight the visibility of the contents of the JFrame when it is initialized or visible.I want to display the files present in the folder selected,but each time whe I start the application I have to resize it.I find it irritating too.Please solve this immediately.
enjoy with java.
Bye for now.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

If you could post some code, that would help. What layout manager are you using for your contentpane and also, are you using the pack() method or setting a static size and position for the JFrame? The pack() method will automattically adjust the size of your JFrame upon opening it to fit all your components inside it.

Happy Coding,
Gregg Bolinger

GenRocket - Experts at Building Test Data
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
I don't use the pack() method.
I have solved the problem.If the setVisible() methos is called
when the JFrame object is created it's contents ara also visible without resizing.anyhow helpme with the pack()method().
import javax.swing.*;
import java.awt.*;
public class SampJFrame extends JFrame
public SampJFrame()
setTitle("Mr.Clean,The Disk_Space Optimizer");
String spac=" ";
Container con=getContentPane();
JLabel title=new JLabel(spac+"Kick out uninvited Guests R..i..g..h..t NOW!!");
JPanel p1=new JPanel();
p1.setLayout(new BorderLayout());
JTextArea lfile=new JTextArea("",10,30);
JScrollPane jsp=new JScrollPane(lfile);
JPanel p2=new JPanel();
p2.setLayout(new BorderLayout());
con.setLayout(new BorderLayout());
public static void main(String args[])
new SampJFrame().setVisible(true);
end of code: ***************************************
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi Netharam,
call setSize()/setVisible/pack() after laying out the components. I think I read once about something like: the components are actually layed out when calling one of these methods.
on second thought: why calling setSize() etc. in your code anyway, your extending JFrame. it's not the task of the JFrame to set its own size or visibility (consider the JFrame API!). if you want to do this, don't use inheritance, use composition. otherwise, call setSize() etc. from outside this frame. (of course you can overwrite the setSize() method for this frame, if necessary.)
pack() is a fine thing. if you use it you don't need setSize() (and vice versa). the one method of the two that is called last will actually cause effect. if you use pack(), then specify the preferred size of your components. pack() will use it if the components get bigger. if they remain smaller, it will resize the frame to fit. using pack() requires a well implemented layout management (together with the GridBagLayout its a fine thing).
have fun
I agree. Here's the link: http://aspose.com/file-tools
subject: visualising the contents of the frame without resizing[urgent]
It's not a secret anymore!