swing 介面操作開啟檔案對話方塊
阿新 • • 發佈:2018-12-26
為按鈕jbselect增加監聽:
jbselect.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jchooser1 = new JFileChooser();<span style="white-space:pre"> </span>//JFileChooser控制元件 jchooser1.setCurrentDirectory(new File("c:/")); int index = jchooser1.showOpenDialog(getContentPane()); if(index == JFileChooser.APPROVE_OPTION){ @SuppressWarnings("unused") File selectedFile = jchooser1.getSelectedFile(); jtxdb.setText(jchooser1.getSelectedFile().getAbsolutePath()); dblist = ck.DBList(jtxdb.getText()); } } });