title: How to store the recent items permanently using swing
body: <p>I want to add recent opened files to recent menu.I did that task.But,it doesn't store permanently.That means when i close the running application,the recent items also removed.I want to store the recent items permanently,after re run the application the recent open items are available. </p>
  
  <p>My Code:</p>
  
  <pre><code>public class RecentItems extends javax.swing.JFrame {
  int i=0;
  Queue&lt;String&gt; q;
  JMenuItem item;
  String recentPath;
  int recentItems_count=0;
  JTextPane textPane;
  JScrollPane scrollPane;
  public RecentItems() {
      initComponents();
      q=new LinkedList&lt;&gt;();
      textPane=new JTextPane();
      scrollPane=new JScrollPane(textPane);
  }
  @SuppressWarnings("unchecked")
  // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
  private void initComponents() {
  
      tp = new javax.swing.JTabbedPane();
      jMenuBar1 = new javax.swing.JMenuBar();
      jMenu1 = new javax.swing.JMenu();
      openAction = new javax.swing.JMenuItem();
      recentItems = new javax.swing.JMenu();
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
      jMenu1.setText("File");
  
      openAction.setText("OPEN");
      openAction.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              openActionActionPerformed(evt);
          }
      });
      jMenu1.add(openAction);
  
      recentItems.setText("Recent");
      jMenu1.add(recentItems);
  
      jMenuBar1.add(jMenu1);
  
      setJMenuBar(jMenuBar1);
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(tp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(tp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
      );
  
      pack();
  }// &lt;/editor-fold&gt;                        
  
  private void openActionActionPerformed(java.awt.event.ActionEvent evt) {                                           
      FileDialog fd = new FileDialog(RecentItems.this, "Select File", FileDialog.LOAD);
      fd.setVisible(true);
      String title;
      String sts;
      File file;
      if (fd.getFile() != null) {
          sts = fd.getDirectory() + fd.getFile();
          file=new File(sts);
          title=fd.getFile();
          JInternalFrame internalFrame = new JInternalFrame("",true,true); 
          i++;
          internalFrame.setName("Doc "+i);
          internalFrame.setTitle(title);
          try {
              internalFrame.setSelected(true);
          } 
          catch (PropertyVetoException ex) {
              Logger.getLogger(RecentItems.class.getName()).log(Level.SEVERE, null, ex);
          }      
          internalFrame.add(scrollPane);
          tp.add(internalFrame);
          try{
              tp.setSelectedIndex(i-1);  
          }
          catch(IndexOutOfBoundsException ioe){   
          }
          try {
              textPane.setPage(file.toURI().toURL());
          } 
          catch (MalformedURLException ex) {
              Logger.getLogger(RecentItems.class.getName()).log(Level.SEVERE, null, ex);
          }
          catch (IOException ex) {
              Logger.getLogger(RecentItems.class.getName()).log(Level.SEVERE, null, ex);
          }
          setVisible(true);
          textPane.setCaretPosition(0);
          q.add(sts);
          recentItems_count++;              
          if(recentItems_count&gt;1) {
              int size=q.size();
              String[] strArray = new String[q.size()];
              q.toArray(strArray);
              for(int k=0;k&lt;size;k++) {
                  for(int i=size-1;i&gt;k;i--) {
                      if(strArray[k].equals(strArray[i])) {  
                          q.remove(strArray[k]); 
                          tp.remove(internalFrame);
                      }
                  }
              }
          } 
          if(q.size()&lt;=3) {
              recentItems.removeAll();
              for( String string : q) {  
                  item=recentItems.add(string);
                  recentPath=item.getText();
              }
          }
          else if(q.size()&gt;3) {
              q.remove();
              recentItems.removeAll();
              for( String string : q)  {
                  item=recentItems.add(string);
                  recentPath=item.getText();
              }
          }
      }
  }                                          
  
  public static void main(String args[]) {
      try {
          for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
              if ("Nimbus".equals(info.getName())) {
                  javax.swing.UIManager.setLookAndFeel(info.getClassName());
                  break;
              }
          }
      } catch (ClassNotFoundException ex) {
          java.util.logging.Logger.getLogger(RecentItems.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (InstantiationException ex) {
          java.util.logging.Logger.getLogger(RecentItems.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
          java.util.logging.Logger.getLogger(RecentItems.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (javax.swing.UnsupportedLookAndFeelException ex) {
          java.util.logging.Logger.getLogger(RecentItems.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      }
      java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
              new RecentItems().setVisible(true);
          }
      });
  }                    
  private javax.swing.JMenu jMenu1;
  private javax.swing.JMenuBar jMenuBar1;
  private javax.swing.JMenuItem openAction;
  private javax.swing.JMenu recentItems;
  private javax.swing.JTabbedPane tp;                
  }
  </code></pre>