ksfok
asked on
Java window component bug
Given the below java code:
import java.awt.*;
import javax.swing.*;
public class WindowSwing {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Windows Asgn");
frame.setSize(400, 150);
frame.setDefaultCloseOpera tion(JFram e.EXIT_ON_ CLOSE);
//Create container
Container content = frame.getContentPane();
//Add JButton
JButton button = new JButton("JButton");
content.add(button);
//Add JLabel.
JLabel label = new JLabel("Enter Your First Name Below:");
content.add(label);
//Add JtextField
JTextField textFld = new JTextField();
content.add(textFld);
//Display the window.
frame.pack();
frame.setVisible(true);
//frame.addWindowListener( new ExitListener());
//frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities .invokeLat er(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
The window run is very small. None of the components show. Why? Please advise.
Thanks.
import java.awt.*;
import javax.swing.*;
public class WindowSwing {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Windows Asgn");
frame.setSize(400, 150);
frame.setDefaultCloseOpera
//Create container
Container content = frame.getContentPane();
//Add JButton
JButton button = new JButton("JButton");
content.add(button);
//Add JLabel.
JLabel label = new JLabel("Enter Your First Name Below:");
content.add(label);
//Add JtextField
JTextField textFld = new JTextField();
content.add(textFld);
//Display the window.
frame.pack();
frame.setVisible(true);
//frame.addWindowListener(
//frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities
public void run() {
createAndShowGUI();
}
});
}
}
The window run is very small. None of the components show. Why? Please advise.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.