티스토리 뷰

기본적으로 입력하는 컴퓨터에서 다음 작업을 수행합니다.

package stackoverflow;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 *
  * @author ub
   */
   public class StackOverflow
   {
   
       /**
            * @param args the command line arguments
                 */
                     public static void main(String[] args)
                         {
                                 JFileChooser chooser = new JFileChooser();
                                         FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "gif","png");
                                                 chooser.setFileFilter(filter);
                                                         chooser.setSelectedFile(new File("C:\\Users\\ub\\Pictures\\Capt.PNG"));
                                                                 int returnVal = chooser.showOpenDialog(null);
                                                                         if(returnVal == JFileChooser.APPROVE_OPTION)
                                                                                    System.out.println("You chose to open this file: "+chooser.getSelectedFile().getName());
                                                                                        }
                                                                                        
                                                                                        }
                                                                                        
-------------------

처음 호출 .setSelectedFilefilepath빈 문자열 이기 때문 입니다.

사용자 에게 파일 선택기를 표시 한 후filepath 변수를 설정합니다 .

filepath호출하기 직전에 의 문자열 값을 콘솔에 인쇄하면 .showDialog이것을 볼 수 있습니다.

-------------------

문제는 다음 줄로 인해 발생한 것 같습니다.

try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                                    break;
                                            }
                                                }
                                                } catch (ClassNotFoundException ex) {
                                                java.util.logging.Logger.getLogger(Editor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                                                } catch (InstantiationException ex) {
                                                java.util.logging.Logger.getLogger(Editor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                                                } catch (IllegalAccessException ex) {
                                                java.util.logging.Logger.getLogger(Editor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                                                } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                                                java.util.logging.Logger.getLogger(Editor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                                                }
                                                

제거되면 Unai Vivi의 예와 같이 파일 이름이 강조 표시됩니다.



출처
https://stackoverflow.com/questions/39916878
댓글
공지사항
Total
Today
Yesterday
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30