title: Refresh elements of GUI in java
body: <p>I'm new to GUIs in java. </p>
  
  <p>For example, I need to update just 1 element (e.g., <code>JLabel</code>). In Tkinter I would use something like <code>root.update()</code> or <code>root.update_idletasks()</code>. I wonder if a similar simple function exists in for applications made with swing. I've tried <code>gui_element.SetVisible(false)</code> and <code>gui_element.SetVisible(true)</code> and similar stuff, but not very successfully. I suspect something with <code>javax.swing.Timer</code> should work, but do not know how.  </p>
  
  <p><strong>EDIT</strong> Here is the code. Please let me know if you find other errors. Thanks </p>
  
  <pre><code>import java.awt.Color;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.BorderFactory;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JOptionPane;
  
  public class sof_sample{
  
      /**
       * @param args
       */
  
      private static JFrame frame1 = new JFrame("Fractal Geometry");
      public static JButton quit_button = new JButton("Quit");
      private static JButton run_button = new JButton("Run");
      private static JLabel label1 = new JLabel();
      public static JLabel label_iter = new JLabel(); 
      private static GridLayout layout1 = new GridLayout(2,20);
      private JOptionPane msg1 = new JOptionPane();
      private static int counter;
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          AuxClass1 inst1 = new AuxClass1();
          quit_button.addActionListener(inst1);
          run_button.addActionListener(inst1);
          label1.setText("Iteration");
          label1.setVerticalTextPosition(JLabel.CENTER);
          label1.setHorizontalAlignment(JLabel.CENTER);
          label_iter.setText("0");
          label_iter.setBorder(BorderFactory.createLineBorder(Color.BLACK));      
          label_iter.setVerticalTextPosition(JLabel.CENTER);
          label_iter.setHorizontalAlignment(JLabel.CENTER);
  
          //add widgets to the frame
          frame1.add(label1);
          frame1.add(label_iter);
          frame1.add(run_button);
          frame1.add(quit_button);
  
          frame1.setLayout(layout1);
          frame1.setLocationRelativeTo(null);
          //frame1.pack();
          frame1.setSize(250, 75);
          frame1.setVisible(true);
  
      }
  
  }
  
  class AuxClass1 implements ActionListener{
      sof_sample inst2 = new sof_sample();
  
      public void actionPerformed(ActionEvent event1){
  
          if (event1.getSource()==inst2.quit_button){
              System.exit(0);
  
          }
          else{
              for (int i=0;i&lt;20000;i++){
  
                  inst2.label_iter.setText(Integer.toString(i));
  
              }
              //msg1.showMessageDialog(frame1, "Not yet!");
  
          }
  
  
      }
  
  
  
  }
  </code></pre>