title: Reload/Refresh JFrame window on button click
body: <p>I have tried a lot of thinks in last two days and I just can't refresh the Frame :/
  I connect on my database and make a select query... In my console window I see 4 ID-s On my form too... After I make another data in my database, in my console window i see 5 ID-s but on my form 4... If I put <code>frame.setvisible</code> on my button another form appears...</p>
  
  <p>Here is my class:</p>
  
  <pre><code>JLabel timeLabel;
  
  
  private JPanel contentPane;
   private ArrayList&lt;JLabel&gt; lbllist= new ArrayList&lt;JLabel&gt;();
   private ArrayList&lt;JButton&gt; btnlist= new ArrayList&lt;JButton&gt;();
  static int brojac = 0;
  private JLabel lblNewLabel;
  private JButton btnRefresh;
  
  public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
          public void run() {
              try {
  
  
                  Mainframe = new Main();
                  frame.setVisible(true);
  
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      });
  }
             //constructor (I need every time to see data from the database)
                 public Main() {
  
  
      getContentPane().setLayout(null);
  
      lblNewLabel = new JLabel("New label");
      lblNewLabel.setBounds(0, 185, 46, 14);
      getContentPane().add(lblNewLabel);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(100, 100, 800, 300);
      contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.setLayout(null);
  
      getContentPane().removeAll();
      btnRefresh = new JButton("Refresh");
      btnRefresh.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
              do_btnRefresh_actionPerformed(arg0);
          }
      });
      btnRefresh.setBounds(335, 228, 89, 23);
      contentPane.add(btnRefresh);
  
      EntityManager em = Connection.getEmf().createEntityManager();
      TypedQuery&lt;Entity&gt; query = em.createQuery(
              "select n from Entityn where finished= 0",
              PokusajNarudzbe.class);
      List&lt;Entity&gt; resultList = query.getResultList();
      int a = 20;
      for (Entitypokusaj entity: resultList) {
  
          System.err.println(entity.getName());//here i see all data (but not
                                                     //in the form
  
          JLabel list= new JLabel(entity.getBrojName());
          lista.setBounds(10, a, 200, 20);
          lista.setText(entity.getNarudzbaID() + " "
                  + entity.Name() + " ";
          lbllist.add(list);
          getContentPane().add(list);
          list.setVisible(true);
          list.repaint();
          list.revalidate();
          JButton btn= new JButton(entity.getName());
          btn.setBounds(500, a, 200, 20);
          btn.setText("Gotovo");
          btnlist.add(btn);
          getContentPane().add(btn);
          a += 20;
          gumb.setVisible(true);
          gumb.repaint();
          gumb.revalidate();
      }
  
      getContentPane().repaint();
      resultList.clear();
      em.clear();
      em.close();
  
  }
  `               protected void do_btnRefresh_actionPerformed(ActionEvent arg0) {
      Main frame1 = new Main();
      SwingUtilities.updateComponentTreeUI(frame1);
      frame1.invalidate();
      frame1.validate();
      frame1.repaint();
  //      frame1.revalidate();
  //      frame1.setVisible(true); (if I uncomment this another form apears...)
  
  }
  
  
  @Override
  public int read(CharBuffer arg0) throws IOException {
      // TODO Auto-generated method stub
      return 0;
  }
  }
  </code></pre>
  
  <p>What can I do?</p>