0

I am trying to create JButtons and add them to a JScrollPane as well as a vector of JButtons. When I try to add them to the vector the program throws an exception.

Here is the code:

public class DirectorySelectionWindow extends JFrame {

Vector<JButton> directoryButtons;
String selectedDir;

DirectorySelectionWindow(){
    super("Select Directory");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String cwd = System.getProperty("user.dir");
    System.out.println(cwd);

    File currentDirectory = new File(cwd);

    String filesInDir[] = currentDirectory.list();

    JScrollPane pane = new JScrollPane();

    for (int i = 0; i < filesInDir.length; i++) {
        if (filesInDir[i] != null) {
            if (!filesInDir[i].toString().startsWith(".")) {
                System.out.println(filesInDir[i]);
                JButton button = new JButton(filesInDir[i]);
                directoryButtons.addElement(button);
                pane.add(directoryButtons.elementAt(i));
            }
        }
    }

    this.add(pane);
    this.pack();
    this.setVisible(true);
    }

I catch the exception when I try to add the button to the vector (the directoryButtons.add() line).

Jack Frye
  • 583
  • 1
  • 7
  • 28

0 Answers0