• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to set the size of the default window in swing  RSS feed

 
vikram nalagampalli
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I nevwe worked with swing and i am trying to do a sample application. can any one please tell me how to set the size of the default window that shows up where i have all my component

My constructor looks like below
public WordXMLMain(){
super(new BorderLayout());

// Label initilization
lblFileName = new JLabel();
//fileName.setEditable(false);
// Text Area initilization
txtOutput = new JTextArea(5,20);
txtOutput.setMargin(new Insets(10,10,10,10));
txtOutput.setLineWrap(true);
txtOutput.setSize(250, 500);
txtOutput.setEditable(false);
JScrollPane outputScrollPane = new JScrollPane(txtOutput);
outputScrollPane.setSize(250,500);

fc = new JFileChooser();
// Button Initilization
btnOpenFile = new JButton("Choose File");
btnOpenFile.addActionListener(this);
btnOpenFile.setActionCommand("open");

btnProcessFile = new JButton("Process File");
btnProcessFile.addActionListener(this);
btnProcessFile.setActionCommand("process");

JPanel panel = new JPanel();

panel.add(btnOpenFile);
panel.add(lblFileName);
//panel.add(btnProcessFile);

JPanel panel1 = new JPanel();
panel1.add(btnProcessFile);

add(panel, BorderLayout.BEFORE_FIRST_LINE);

add(outputScrollPane, BorderLayout.CENTER);
add(panel1, BorderLayout.SOUTH);

setSize(250,500);
setVisible(true);



}
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After adding and sizing all of the components, try this:

The call to "pack()" lets the layout manager size and position each component for display, and then sets the default size of the container so each component is visible (if there is enough room on the screen).
[ December 19, 2003: Message edited by: Wayne L Johnson ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!