How do I set default file path location in windows builder eclipse (java)

1.4k views Asked by At

I am making a software which will pick only default directory after installation and from that file(in directory) a button will be linked to perform the task. I am unable to set and show default path which will look exactly like the given example in windows builder. It must be hard coded.

Example:-
hard coded defined file path

private void initialize() {
        frmPdfPublisher = new JFrame();
        frmPdfPublisher.setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Admin\\Desktop\\imageedit_1_6449501097.png"));
        frmPdfPublisher.setTitle("PDF Publisher");
        frmPdfPublisher.setBounds(100, 100, 450, 439);
        frmPdfPublisher.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frmPdfPublisher.getContentPane().setLayout(null);

        JButton btnTransform = new JButton("Transform");
        btnTransform.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

            }
        });
        btnTransform.setBounds(76, 167, 89, 23);
        frmPdfPublisher.getContentPane().add(btnTransform);

        JButton btnPreview = new JButton("Preview");
        btnPreview.setBounds(269, 167, 89, 23);
        frmPdfPublisher.getContentPane().add(btnPreview);

        JProgressBar progressBar = new JProgressBar();
        progressBar.setBounds(138, 218, 146, 14);
        frmPdfPublisher.getContentPane().add(progressBar);



        JButton btnQuit = new JButton("Quit");
        btnQuit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        btnQuit.setBounds(176, 288, 89, 23);
        frmPdfPublisher.getContentPane().add(btnQuit);

        JLabel lblLabel1 = new JLabel("Default DITA-OT File :");
        lblLabel1.setBounds(10, 79, 123, 14);
        frmPdfPublisher.getContentPane().add(lblLabel1);





        JSeparator separator = new JSeparator();
        separator.setBounds(10, 140, 414, 2);
        frmPdfPublisher.getContentPane().add(separator);

        JSeparator separator_1 = new JSeparator();
        separator_1.setBounds(10, 257, 414, 2);
        frmPdfPublisher.getContentPane().add(separator_1);

        textField_1 = new JTextField();
        textField_1.setBackground(SystemColor.menu);
        textField_1.setBounds(138, 76, 286, 20);
        frmPdfPublisher.getContentPane().add(textField_1);
        textField_1.setColumns(10);
        textField_1.setBorder(null);
        textField_1.setText(System.getProperty("C:/Program Files/dita-ot-2.4"));



        JMenuBar menuBar = new JMenuBar();
        frmPdfPublisher.setJMenuBar(menuBar);

        JMenu mnHelp = new JMenu("Option");
        menuBar.add(mnHelp);

        JMenuItem mntmHelp = new JMenuItem("Help");
        mnHelp.add(mntmHelp);
    }
}
1

There are 1 answers

7
newuserua_ext On

See here for a list of system properties and their descriptions.

Instead of this ;

textField_1.setText(System.getProperty("C:/Program Files/dita-ot-2.4"));

Use this ;

textField_1.setText(System.getProperty("user.dir"));

If you want to use absolute path then you should use ;

textField_1.setText("C:/Program Files/dita-ot-2.4");