title: Add jdatepicker in jpanel
body: <p>I am trying to add jdatepicker in jpanel, this jpanel is called inside jframe, the problem is that if I try to add jdatepicker directly into jpanel it is not displayed, until some event is performed.</p>
  
  <p>I have tried <a href="https://stackoverflow.com/questions/25933567/add-this-jdatepicker-in-jpanel-instead-jframe-in-java">this</a> solution, but this was of no help. When I use this it also open one more window with no data.</p>
  
  <p>and other method I am using is - </p>
  
  <p>Class MainApp which is using frame</p>
  
  <pre><code>public class MainApp extends JFrame implements ActionListener {
  
  private JPanel panel;
  
  private JMenuBar m_menuBar;
  private JMenu m_menuSales;
  
  private JMenuItem m_itmSalesNewBuisness;
  private JMenuItem m_itmSalesAppointments;
  
  private static MainApp instance = null;
  
  public static MainApp getInstance() {
      if(instance == null) {
          instance = new MainApp();
      }
  
      return instance;
  }
  
  private MainApp() {
      initComponents();
  }
  
  private void initComponents() {
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      m_menuBar = new JMenuBar();
      m_menuSales = new JMenu("Sales");
      m_itmSalesAppointments = new JMenuItem("Appointments");
      m_itmSalesAppointments.addActionListener(this);
      m_itmSalesNewBuisness = new JMenuItem("New Business");
      m_itmSalesNewBuisness.addActionListener(this);
  
      m_menuBar.add(m_menuSales);
      setJMenuBar(m_menuBar);
  
      setSize(1300, 700);
      setVisible(true);
  }
  
  public static void main(String[] args) {
      try {
          UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
      } catch (UnsupportedLookAndFeelException ex) {
          ex.printStackTrace();
      } catch (IllegalAccessException ex) {
          ex.printStackTrace();
      } catch (InstantiationException ex) {
          ex.printStackTrace();
      } catch (ClassNotFoundException ex) {
          ex.printStackTrace();
      }
      UIManager.put("swing.boldMetal", Boolean.FALSE);
  
      SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
              new MainApp();
          }
      });
  }
  
  @Override
  public void actionPerformed(ActionEvent e) {
      if(m_itmSalesNewBuisness == e.getSource()){
          if(panel != null) {
              remove(panel);
              invalidate();
          }
          revalidate();
          repaint();
          panel = new CopyOfNewBusiness();
          panel.setBounds(0, 0, getWidth(), getHeight());
          add(panel);
      } else if(m_itmSalesAppointments == e.getSource()){
          if(panel != null) {
              remove(panel);
              invalidate();
          }
          revalidate();
          repaint();
          panel = new AppointmentTracker();
          panel.setBounds(0, 0, getWidth(), getHeight());
          add(panel);
      }
  }
  
  public JDatePickerImpl setDatePicker() {
      UtilDateModel model = new UtilDateModel();
      model.setSelected(true);
      JDatePanelImpl datePanel = new JDatePanelImpl(model);
      JDatePickerImpl datePicker = new JDatePickerImpl(datePanel, new DateLabelFormatter());
      return datePicker;      
  }
  </code></pre>
  
  <p>NewBusiness.java</p>
  
  <pre><code>public class CopyOfNewBusiness extends JPanel implements ActionListener, ItemListener {
  
  private JLabel m_lblDate;
  private JDatePickerImpl m_dtpDate;
  
  private JLabel m_lblFollowUpDate;
  private UtilDateModel followUpDateModel;
  private JDatePanelImpl followUpDatePanel;
  private JDatePickerImpl m_dtpFollowUp;
  
  public CopyOfNewBusiness() {
      initComponents();
  }
  
  private void initComponents() {
      setLayout(null);
  
      m_lblDate = new JLabel("Date");
      m_lblDate.setBounds(10, 10, 100, 30);
      add(m_lblDate);
  
      m_dtpDate = MainApp.getInstance().setDatePicker();
      m_dtpDate.setBounds(120, 10, 120, 30);
      add(m_dtpDate);
  
      m_lblFollowUpDate = new JLabel("Follow Up Date");
      m_lblFollowUpDate.setBounds(10, 370, 100, 30);
      add(m_lblFollowUpDate);
  
      followUpDateModel = new UtilDateModel();
      followUpDatePanel = new JDatePanelImpl(followUpDateModel);
      m_dtpFollowUp = new JDatePickerImpl(followUpDatePanel);
      m_dtpFollowUp.setBounds(120, 370, 120, 30);
      add(m_dtpFollowUp);
  
      setPreferredSize(new Dimension(getWidth(), getHeight()));
  }
  </code></pre>
  
  <p>}</p>