1 Replies - 799 Views - Last Post: 08 November 2011 - 09:38 AM Rate Topic: ***-- 2 Votes

#1 rosebrit3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 02-November 11

Properties File in Java

Posted 08 November 2011 - 07:31 AM

Hai all,

I am doing a Project where I have to create an Application that contains a GUI. The user has to enter the details for the textfields. These has to be stored in a Properties File and then the value that the user has entered the previous time have to be loaded again the next time the user opens the GUI. Since, its a Project, I have modularised the code into classes. I am writing the code below.

It contains a Frame, contianing a menubar, on clicking a menuitem a dialog window is opened, which consists of a TabbedPane. In the First Tab, called DatabaseOptions, the user enters the name and value. These two are the textfields which I want to store in the Properties file and retrieve them again on loading the GUI.

    public class Main {
    public static void main (String args[])
        MainMenu v=new MainMenu();

    public class MainMenu extends javax.swing.JFrame {

    Properties props=new Properties();
    /** Creates new form MainMenu */
    public MainMenu() {
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

         private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)                                                
            ReportOptions mf=new ReportOptions(this, true);
            UserInformation ui=new UserInformation();


public class ReportOptions extends javax.swing.JDialog {

    /** Creates new form ReportOptions */
    public ReportOptions(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        addOptionPage(new DatabaseOptions(), "DatabaseOptions");
        addOptionPage(new TableOptions(), "ReportOptions");

   private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
       UserInformation ui=new UserInformation();
        try {
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ReportOptions.class.getName()).log(Level.SEVERE, null, ex);
   public void addOptionPage(JPanel p, String title ) {
        this.jTabbedPane1.addTab(title, p );        


public class DatabaseOptions extends javax.swing.JPanel {

    /** Creates new form DatabaseOptions */
    public DatabaseOptions() {

 private void initComponents() {

        NameLabel = new javax.swing.JLabel();
        ValueLabel = new javax.swing.JLabel();
        NameText = new javax.swing.JTextField();
        ValueText = new javax.swing.JTextField();

Now, I have created anew class called FileInformation, contianing two methods, getInformation() and setInformation(). I want these methods to contain the code for getting and setting the key and value pairs in the Properties file. Can anyone help me in guiding me how to do this, please?

Thank You all.

Is This A Good Question/Topic? 0
  • +

Replies To: Properties File in Java

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon

Reputation: 10183
  • View blog
  • Posts: 37,596
  • Joined: 27-December 08

Re: Properties File in Java

Posted 08 November 2011 - 09:38 AM

Check out this File I/O Tutorial. Also, please avoid the NetBeans GUI Builder. It produces horrid, unmaintainable code that humans can neither read nor maintain. Write your code by hand instead.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1