如何在windows builder eclipse(java)中设置默认文件路径位置

时间:2016-12-29 06:10:38

标签: java eclipse windowbuilder

我正在制作一个软件,它将在安装后只选择默认目录,并从该文件(在目录中)链接一个按钮来执行任务。我无法设置和显示默认路径,它看起来与Windows构建器中的给定示例完全相同。它必须是硬编码的。

实施例: -
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 个答案:

答案 0 :(得分:0)

有关系统属性及其说明的列表,请参阅here

而不是这个;

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

使用此;

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

如果你想使用绝对路径,你应该使用;

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