I have written a login window, and if I would use the setBounds() to define the size of the frame, all of the components are visible. But using the pack() the frame shrink to the minmal, and there is no any component to be displayed.
public class Window extends JFrame {
public Window() {
setTitle("Login");
setLocationRelativeTo(null);
setSize(new Dimension(200, 130));
pack(); // it make the frame shrink to the minimal
JLabel lblUser = new JLabel("User:");
lblUser.setPreferredSize(new Dimension(10, 0));
lblUser.setHorizontalAlignment(SwingConstants.RIGHT);
TextField txtUser = new TextField(10);
JLabel lblPassword = new JLabel("Password:");
lblPassword.setPreferredSize(new Dimension(10, 0));
lblPassword.setHorizontalAlignment(SwingConstants.RIGHT);
TextField txtPassword = new TextField(10);
JPanel pnlData = new JPanel(new GridLayout(2, 2, 5, 5));
Border titleBorder = new TitledBorder("Login");
pnlData.setBorder(titleBorder);
pnlData.add(lblUser);
pnlData.add(txtUser);
pnlData.add(lblPassword);
pnlData.add(txtPassword);
JButton jbtOk = new JButton("OK");
JButton jbtCancel = new JButton("Cancel");
JPanel pnlButton = new JPanel(new FlowLayout(CENTER, 10, 0));
pnlButton.add(jbtOk);
pnlButton.add(jbtCancel);
Box boxOutter = Box.createVerticalBox();
boxOutter.add(pnlData);
boxOutter.add(pnlButton);
add(boxOutter);
setVisible(true);
}
}