/** Implementing the action of pressing the ok button. */ public void okButton_actionPerformed() { String file = null; file = fileChooser.getFileName(); fileChooser.setCurrentFileName(file); setVisible(false); if (!(file == null)) { notifyListeners(file); } }
/** Called when the user pressed the enter button. */ @Override public void enterPressed() { String file = null; file = fileChooser.getFileName(); fileChooser.setCurrentFileName(file); if (!(file == null)) { notifyListeners(file); } setVisible(false); }
// Initialization. private void jbInit() { fileChooser.addListener(this); fileChooser.setWindowLocation(647, 3); this.getContentPane().setLayout(null); setTitle("Files selection"); fileChooser.setBounds(new Rectangle(5, 2, 482, 48)); okButton.setToolTipText("OK"); okButton.setIcon(okIcon); okButton.setBounds(new Rectangle(124, 64, 63, 44)); okButton.addActionListener(e -> okButton_actionPerformed()); cancelButton.setBounds(new Rectangle(282, 63, 63, 44)); cancelButton.addActionListener(e -> cancelButton_actionPerformed()); cancelButton.setToolTipText("CANCEL"); cancelButton.setIcon(cancelIcon); this.getContentPane().add(fileChooser, null); this.getContentPane().add(cancelButton, null); this.getContentPane().add(okButton, null); setSize(496, 150); setLocation(145, 250); }
/** Constructs a new FilesChooserWindow. */ public FileChooserWindow(FileFilter filter) { listeners = new Vector<FilesTypeListener>(); fileChooser = new ViewableFileChooserComponent(); fileChooser.setFilter(filter); try { okIcon = new ImageIcon(Paths.get(ClassLoader.getSystemResource("ok.gif").toURI()).toString()); cancelIcon = new ImageIcon(Paths.get(ClassLoader.getSystemResource("cancel.gif").toURI()).toString()); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } jbInit(); }
/** Returns the textfield. */ public JTextField getTextField() { return fileChooser.getTextField(); }
/** Implementing the action of pressing the cancel button. */ public void cancelButton_actionPerformed() { fileChooser.showCurrentFileName(); setVisible(false); }
/** Shows the file chooser window. */ public void showWindow() { setVisible(true); fileChooser.getTextField().requestFocus(); }
/** Sets the name of the file chooser. */ @Override public void setName(String name) { fileChooser.setName(name); }
/** Sets the file name (which is written inside the text field). */ public void setFileName(String name) { fileChooser.setCurrentFileName(name); fileChooser.showCurrentFileName(); }