• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

visualising the contents of the frame without resizing[urgent]

 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Netharam
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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().
code:****************************************************
import javax.swing.*;
import java.awt.*;
public class SampJFrame extends JFrame
{
public SampJFrame()
{
setSize(400,400);
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());
p1.add("North",title);
JTextArea lfile=new JTextArea("",10,30);
lfile.setEditable(false);
lfile.setLineWrap(true);
JScrollPane jsp=new JScrollPane(lfile);
JPanel p2=new JPanel();
p2.setLayout(new BorderLayout());
p2.add("Center",jsp);
con.setLayout(new BorderLayout());
con.add("North",p1);
con.add("Center",p2);
}
public static void main(String args[])
{
new SampJFrame().setVisible(true);
}
}
end of code: ***************************************
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
chantal
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic