Problems with jfilechooser in Mac OS

Source: Internet
Author: User

To download FTP to a local system, you need to open a file storage dialog box. The local operating system must support windows, Linux, and Mac. Therefore, Java javax. Swing. jfilechooser should be used;

So I wrote a testProgramAs follows:

 

Code

Public   Static   Void Main (string [] ARGs ){
String retstr =   "" ;
Jfilechooser C = New Jfilechooser ();
C. setfileselectionmode (jfilechooser. directories_only );
C. setdialogtitle ( " Select the target folder to download " );
C. setdialogtype (jfilechooser. save_dialog );
Int RET = C. showsavedialog ( Null );
If (Ret = Jfilechooser. cancel_option ){
Retstr =   "" ;
}
Else   If (Ret = Jfilechooser. approve_option ){
Retstr = C. getselectedfile (). getabsolutepath ();
System. Out. println (retstr );
// System. Out. println (system. getproperty ("OS. Name "));

}
Else   If (Ret = Jfilechooser. error_option ){
Retstr =   "" ;
}
}

 

 

Running in Windows is normal. The saved folder address can be obtained normally, but it is found strange in Mac. For example, if/volume/ftptest/is selected and double-click to open it, the obtained path will be/volume/ftptest/, that is, the target folder will be repeated. However, if the folder is directly selected but not entered, the correct path will be returned...

 

It is preliminarily determined that showsavedialog of jfilechooser does not support cross-platform platforms, or that the MAC system does not support Java well. Later I searched for a solution and found the solution on a foreigner's blog:

The problem occurs when you use chooser. showdialog or chooser. showsavedialog instead of chooser. showopendialog. on XP chooser. showdialog returns the correct path under the example given by the op, but on Mac OS 10.5.7 (and probably earlier versions as well) You'll get ~ /Desktop.

Do not use showdialog and showsavedialog on Mac ....

 

So, the aboveCodeChange showsavedialog to showopendialog to solve the problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.