private void selectFolder() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(textFolder.getText())); fileChooser.setDialogTitle(CAPTION_SELECT_FOLDER); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setApproveButtonText("Select"); fileChooser.setApproveButtonToolTipText(TOOL_TIP_SELECT_FOLDER); if (fileChooser.showOpenDialog(FileTransferServer.this) == JFileChooser.APPROVE_OPTION) { // Get the selected file String path = fileChooser.getSelectedFile().getPath() + "\\"; textFolder.setText(path); } }
public JFileChooser createFileChooser() { // create a filechooser JFileChooser fc = new JFileChooser(); if (getSwingSet2() != null && getSwingSet2().isDragEnabled()) { fc.setDragEnabled(true); } // set the current directory to be the images directory File swingFile = new File("resources/images/About.jpg"); if (swingFile.exists()) { fc.setCurrentDirectory(swingFile); fc.setSelectedFile(swingFile); } return fc; }
public void takeScreenshot(boolean flag) { BufferedImage bufferedimage; try { Robot robot = new Robot(); Point point = getLocationOnScreen(); Rectangle rectangle = new Rectangle(point.x, point.y, getWidth(), getHeight()); bufferedimage = robot.createScreenCapture(rectangle); } catch (Throwable throwable) { JOptionPane.showMessageDialog( frame, "An error occured while trying to create a screenshot!", "Screenshot Error", 0); return; } String s = null; try { s = getNearestScreenshotFilename(); } catch (IOException ioexception) { if (flag) { JOptionPane.showMessageDialog( frame, "A screenshot directory does not exist, and could not be created!", "No Screenshot Directory", 0); return; } } if (s == null && flag) { JOptionPane.showMessageDialog( frame, "There are too many screenshots in the screenshot directory!\n" + "Delete some screen\n" + "shots and try again.", "Screenshot Directory Full", 0); return; } if (!flag) { final JFileChooser fileChooser = new JFileChooser(); final JDialog fileDialog = createFileChooserDialog(fileChooser, "Save Screenshot", this); final BufferedImage si = bufferedimage; JFileChooser _tmp = fileChooser; fileChooser.setFileSelectionMode(0); fileChooser.addChoosableFileFilter(new imageFileFilter()); fileChooser.setCurrentDirectory(new File("C:/.hack3rClient/Scre/")); fileChooser.setSelectedFile(new File(s)); JFileChooser _tmp1 = fileChooser; fileChooser.setDialogType(1); fileChooser.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionevent) { String s1 = actionevent.getActionCommand(); if (s1.equals("ApproveSelection")) { File file = fileChooser.getSelectedFile(); if (file != null && file.isFile()) { int i = JOptionPane.showConfirmDialog( frame, (new StringBuilder()) .append(file.getAbsolutePath()) .append(" already exists.\n" + "Do you want to replace it?") .toString(), "Save Screenshot", 2); if (i != 0) { return; } } try { ImageIO.write(si, "png", file); // client.pushMessage("Screenshot taken.", 3, "@cr2@ Client"); // JOptionPane.showMessageDialog(frame,"Screenshot Taken"); } catch (IOException ioexception2) { JOptionPane.showMessageDialog( frame, "An error occured while trying to save the screenshot!\n" + "Please make sure you have\n" + " write access to the screenshot directory.", "Screenshot Error", 0); } fileDialog.dispose(); } else if (s1.equals("CancelSelection")) { fileDialog.dispose(); } } { } }); fileDialog.setVisible(true); } else { try { ImageIO.write( bufferedimage, "png", new File((new StringBuilder()).append("C:/.hack3rClient/Scre/").append(s).toString())); JOptionPane.showMessageDialog( frame, "Image has been saved to C:/.hack3rclient/Scre. You can view your images by pushing File>View Images in the menu dropdowns.", "Screenshot manager", JOptionPane.INFORMATION_MESSAGE); // client.pushMessage("Screenshot taken.", 3, "@cr2@ Client"); // JOptionPane.showMessageDialog(frame,"Screenshot taken."); } catch (IOException ioexception1) { JOptionPane.showMessageDialog( frame, "An error occured while trying to save the screenshot!\n" + "Please make sure you have\n" + " write access to the screenshot directory.", "Screenshot Error", 0); } } }
/** Apply default folder to file chooser */ public void applyDefaultFolder(final JFileChooser fileChooser) { fileChooser.setCurrentDirectory(getDefaultFolder()); }