Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8130315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:40:09+00:00 2026-06-06T08:40:09+00:00

I have a rename tool that sets a folder directory, however I created some

  • 0

I have a rename tool that sets a folder directory, however I created some JCheckBox and I want them to be able to change the directory depending on which is selected.

Her is the action listener for the checkbox, it edits the txt field so it looks right on the program but does not actually change the directory.

cbxBlackBerry = new JCheckBox("BlackBerry");
        cbxBlackBerry.addActionListener(
                new ActionListener(){
                    public void actionPerformed(ActionEvent e){
                            if(cbxBlackBerry.isSelected())
                            txtPrefix.setText("x-rimdevice_");
                        else{
                            txtPrefix.setText("");
                        }

                        if(cbxBlackBerry.isSelected())
                            txtDirectory.setText("\\RSASoftToken\\blackberry");
                        else{
                            txtDirectory.setText("");
                        }
                    }
                }
            ); //close addActionListener

this is the code that commands the directory setting

private boolean chooseDirectory(){

        /* Choose the file Directory
         * this will ensure that the class variable directory get the value
         * only when a directory is chosen, then the button Ok will be enabled
         */

        JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setAcceptAllFileFilterUsed(false);

        int returnval = fc.showOpenDialog(this);

        if(returnval == JFileChooser.APPROVE_OPTION){
            directory = fc.getSelectedFile();
            btnOk.setEnabled(true);
            return true;        
        }

        return false;
    }// end chooseDirectory

How do I modify this code to actually change the directory?

if(cbxBlackBerry.isSelected())
                            txtDirectory.setText("\\RSASoftToken\\blackberry");
                        else{
                            txtDirectory.setText("");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:40:10+00:00Added an answer on June 6, 2026 at 8:40 am

    You need a method like this:

    private void setDirectory(File dir) {
      directory = dir;
      txtDirectory.setText(dir.getAbsolutePath());
    }
    

    and where you have code that sets the directory JTextField, call this method instead. So for instance, instead of

    if(cbxBlackBerry.isSelected())
       txtDirectory.setText("\\RSASoftToken\\blackberry");
    else{
       txtDirectory.setText("");
    }
    

    Do something like:

    String dirPath = "";
    if (cbxBlackBerry.isSelected())
       dirPath = BLACKBERRY_PATH; // a constant
    else {
       dirPath = "";
    }
    setDirectory(new File(dirPath));
    

    And at the top of the class, have a constant if need be:

    private static final String BLACKBERRY_PATH = "\\RSASoftToken\\blackberry";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working file rename java tool, now I want to add an
I have some files that I would like to rename using regex and powershell,
I have a file in a different folder I want to rename in perl,
At University we have VS 2005 and it has some refactoring tool like rename,
We have some configuration options for the rename detection heuristics during diff ( log
I have a library called example that I'm installing into my global site-packages directory.
I was wondering if there is any tool that renames folder really quickly, using
I am having some troubles with a jar, and I want to rename all
I have built a query tool that enables a non-technical user to query parts
I have some code that is written in french, that is the variables, class,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.