The Artima Developer Community
Sponsored Link

Java Answers Forum
JFrame

2 replies on 1 page. Most recent reply: Jun 14, 2003 4:05 PM by Chris Dailey

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
jack

Posts: 3
Nickname: mendo
Registered: Jun, 2003

JFrame Posted: Jun 14, 2003 11:09 AM
Reply to this message Reply
Advertisement
i have a class that extends JFrame, With all the Textfields and buttons.

when i run that program, i always have to resize (drag the mouse) the frame to view the components, otherwise, no components will appear. What can i do?

The code of my program:


import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;



public class AddEng extends JFrame{

JLabel no, name, des, date;
JTextField nof, namef, desf, datef;
JButton update, exit;


public AddEng()
{
super("Add new Eng");
Container con = getContentPane();
con.setLayout(new FlowLayout());



no = new JLabel("Eng Code: ");
con.add(no);

nof = new JTextField(5);
con.add(nof);

name = new JLabel("Company name: ");
con.add(name);
namef = new JTextField(30);
con.add(namef);
}



public static void main(String [] args) {
AddEng f = new AddEng();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}


}


Nguyentong ThyVu

Posts: 1
Nickname: thyvubtr
Registered: Apr, 2003

Re: JFrame Posted: Jun 14, 2003 1:44 PM
Reply to this message Reply
u not setSize for ur Frame.
let set size for your frame, and run it again

in when first create a jframe ex: myJFrame set Size for it
myJFrame.setSize(400,500);
or
# import java.awt.*;
in main method add:
myJFame.setSize(new Dimension(400,500));

Chris Dailey

Posts: 56
Nickname: mouse
Registered: Dec, 2002

Re: JFrame Posted: Jun 14, 2003 4:05 PM
Reply to this message Reply
The second option (other than explicitly setting the size) is to use the "pack" method on JFrame (which actually comes from Frame and maybe from Window).

Flat View: This topic has 2 replies on 1 page
Topic: Max Previous Topic   Next Topic Topic: java reports

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use