This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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);



}
 
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 ]
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!