Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 4th, 2012  |  syntax: None  |  size: 1.21 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. JFileChooser from a command line program and popping up Underneath all windows
  2. System.out.println("Please select the file");
  3. JFileChooser fc = new JFileChooser();
  4. int retValue = fc.showOpenDialog(new JPanel());
  5. if(retValue == JFileChooser.APPROVE_OPTION){
  6.     g.inputFile = fc.getSelectedFile();
  7. }else {
  8.     System.out.println("Next time select a file.");
  9.     System.exit(1);
  10. }
  11.        
  12. int retValue = fc.showOpenDialog(new JPanel());
  13.        
  14. public class ChooseFile {
  15.     private JFrame frame;
  16.     public ChooseFile() {
  17.         frame = new JFrame();
  18.  
  19.         frame.setVisible(true);
  20.         BringToFront();
  21.     }
  22.     public File getFile() {
  23.         JFileChooser fc = new JFileChooser();
  24.         if(JFileChooser.APPROVE_OPTION == fc.showOpenDialog(null)){
  25.             frame.setVisible(false);
  26.             return fc.getSelectedFile();
  27.         }else {
  28.             System.out.println("Next time select a file.");
  29.             System.exit(1);
  30.         }
  31.         return null;
  32.     }
  33.  
  34.     private void BringToFront() {                  
  35.                     frame.setExtendedState(JFrame.ICONIFIED);
  36.             frame.setExtendedState(JFrame.NORMAL);
  37.  
  38.     }
  39.  
  40. }
  41.        
  42. System.out.println("Please select the file");
  43. g.inputFile = g.new ChooseFile().getFile();