(1) JFrame.setIconImage(Image),从这个JFrame弹出来的Dialog有同样的Icon

解决方案 »

  1.   

     Answer 
    You can't... at least not directly. 
    The dialog may not have a title bar in some windowing environments...atleast that has been the given rationale behind the lack of such a feature Starting JDK 1.1.7 a resizable dialog will inherit the icon of the owner frame. Owner frame is the one passed in the Dialog's CTOR. If you want to allow a different icon for your dialog from that of your main application frame then you could always create a dummy frame, set the icon on it using the frame.setIconImage(Image); and pass it in the Dialog's CTOR. The dummy frame is never shown. This has implications in term of - Modality of the Dialog 
    Automatic showing/hiding of Dialog when your main application frame is shown/hidden. You can always get around it by listeneing to ComponentEvents on the application frame and showing and hiding the dialog apropriately. 
      

  2.   

    2
    Answer You can use the DIRECTORIES_ONLY option for the setFileSelectionModel method of JFileChooser. For example: 
    import javax.swing.JFileChooser;public class ChooseDir {
       public static void main(String[] args) {
          JFileChooser jfc = new JFileChooser ();
          jfc.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
          System.out.println (jfc.showDialog (null, null));
          System.out.println (jfc.getSelectedFile ());
       }
    }