以下代码由Netbeans 6.8 Mac版本自动生成
public class fileBrowser extends javax.swing.JPanel {
/** Creates new form fileBrowser */
public fileBrowser() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jFileChooser1 = new javax.swing.JFileChooser();
setName("Form"); // NOI18N
jFileChooser1.setName("jFileChooser1"); // NOI18N
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jFileChooser1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jFileChooser1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JFileChooser jFileChooser1;
// End of variables declaration
}
我正在尝试使用以下代码制作一个调用它的按钮(以允许用户选择文件):
private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
fileBrowser fileBrowser = new fileBrowser();
fileBrowser.setVisible(true);//why not working?
}
好吧...当我单击按钮时,我只得到一个空表单...知道错误在哪里吗?
最佳答案
JFileChooser 本身并不是一个组件,就像按钮一样。这是一个对话框。所以这是“正确”工作的。检查 JFileChooser Java 文档以了解如何使用 JFileChooser。
关于java - 为什么 Java Jbutton 没有正确调用 JFileChooser?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2286728/