My Jframe is not viewable during executing my java program.After i just resize the frame, all fields are viewable .After i run the java file from eclipse, the output shows only empty frame and then i resize the window all fields are viewable.
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.table.JTableHeader;
public class DBtoExcel extends JFrame {
JLabel l1, l2, l3, l4, l5, l6, l7, l8, l9;
JTextField tf1, tf2,tf3, tf4, tf5, tf6;
JButton btn1, btn2, upload ,saveAsExcel;
//JPasswordField p1, p2;
JTextArea tf7;
JTable table;
JScrollPane scrollPane;
Vector columnNamesVector;
Vector dataVector;
JComboBox combo = new JComboBox();
JScrollPane pane = new JScrollPane(table);
Vector<String> v = new Vector<String>();
DBtoExcel(){
combo.setEditable(true);
pack();
//setContentPane(pane);
setLocationByPlatform(true);
setResizable(true);
setVisible(true);
setSize(600, 800);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("CUSTOMER INFO");
l1 = new JLabel("Add customer details");
l1.setForeground(Color.blue);
l1.setFont(new Font("Serif", Font.BOLD, 20));
l2 = new JLabel("Firstname:");
l3 = new JLabel("Secondname:");
l4 = new JLabel("Contact No:");
l5 = new JLabel("Email-ID:");
l6 = new JLabel("Country:");
l7 = new JLabel("State:");
l8 = new JLabel("Description:");
l9 = new JLabel("Config upload:");
tf1 = new JTextField();
tf2 = new JTextField();
tf3 = new JTextField();
tf4 = new JTextField();
//p1 = new JPasswordField();
//p2 = new JPasswordField();
tf5 = new JTextField();
tf6 = new JTextField();
tf7 = new JTextArea();
//create table with data
JTable table = new JTable(dataVector, columnNamesVector);
JTableHeader header = table.getTableHeader();
//;
btn1 = new JButton("Submit");
btn2 = new JButton("Clear");
upload = new JButton("Browse");
saveAsExcel = new JButton("Save as Excel");
/* btn1.addActionListener(this);
btn2.addActionListener(this);
upload.addActionListener(this);
saveAsExcel.addActionListener(this);*/
l1.setBounds(100, 30, 400, 30);
l2.setBounds(80, 70, 200, 30);
l3.setBounds(80, 110, 200, 30);
l4.setBounds(80, 150, 200, 30);
l5.setBounds(80, 190, 200, 30);
l6.setBounds(80, 230, 200, 30);
l7.setBounds(80, 270, 200, 30);
l8.setBounds(80, 310, 200, 30);
l9.setBounds(80, 400, 200, 30);
tf1.setBounds(300, 70, 200, 30);
tf2.setBounds(300, 110, 200, 30);
tf3.setBounds(300, 150, 200, 30);
tf4.setBounds(300, 190, 200, 30);
//p1.setBounds(300, 150, 200, 30);
//p2.setBounds(300, 190, 200, 30);
//tf5.setBounds(300, 235, 200, 30);
//combo.setBounds(300, 235, 200, 30);
tf6.setBounds(300, 270, 200, 30);
tf7.setBounds(300, 310, 200, 70);
upload.setBounds(300, 400, 100, 30);
btn1.setBounds(170, 450, 100, 30);
btn2.setBounds(280, 450, 100, 30);
saveAsExcel.setBounds(450, 450, 150, 30);
header.setBounds(80, 500, 800, 30);
table.setBounds(80, 530, 800, 250);
table.setBackground(Color.pink);
add(l1);
add(l2);
add(tf1);
add(l3);
add(tf2);
//add(l4);
//add(p1);
//add(l5);
//add(p2);
add(l4);
add(tf3);
add(l5);
add(tf4);
add(l6);
//add(tf5);
add(l7);
add(tf6);
add(l8);
add(tf7);
add(l9);
add(btn1);
add(upload);
add(btn2);
add(saveAsExcel);
add(header);
add( table );
//add(pane);
}
public static void main(String args[]){
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}
catch (Exception ex){
ex.printStackTrace();
}
System.out.println("enter");
//new Registration();
new DBtoExcel();
}
}`