FileDilaog


    Mar 31 2006 | 6:13 pm
    I want to show a File Dialog box when the user clicks a message-box "read". It opens the FileDialog box, but it opens underneath the Max window-in other words it appears invisible until the Max window is minimised.
    Has anyone had this problem before? Or can anyone help?
    Thanks..
    This is my Java code for the read() function:
    public void read() { FileDialog f = new FileDialog( new Frame(), "Load XML File", FileDialog.LOAD ); f.setModal( true ); f.show(); if( f.getFile() != null ) { this.fName = f.getDirectory() + f.getFile(); if( checkFileName() ) { if( setFileType() ) { post( this.fName + " is a valid filenReading: " + this.fName ); } else { try { bail( "This is not a valid file! Only XML and MIDI files are allowed" ); } catch( MaxRuntimeException mre ) {} } } else { try { bail( "This is not a valid file!" ); } catch( MaxRuntimeException mre ) {} } }
    }

    • Mar 31 2006 | 6:42 pm
      what platform are you on? the following code works for me on OS X 10.4.5
      public void read() {
      SwingUtilities.invokeLater(new Runnable() { public void run() { String fName = null; FileDialog f = new FileDialog( new Frame(), "Load XML File", FileDialog.LOAD ); f.setModal( true ); f.show(); if( f.getFile() != null ) { fName = f.getDirectory() + f.getFile(); post( fName + " is a valid file Reading: " + fName ); } } });
      } this probably has nothing to do with your problem but on OS X it is very important to have UI code dispatched form the event handling thread. without that. this code deadlocks on my machine.
      also...i think it would be nice if when people posted code on the list that the snippet they posted could be compiled and work straightaway without an further editing. just as a courtesy.
      topher
    • Mar 31 2006 | 6:43 pm
      Sorry.
      Just found the openDialog() method of MaxSystem. Problem solved!