Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Java Jbutton没有正确调用JFileChooser?_Java_Swing_Netbeans6.8_Jfilechooser - Fatal编程技术网

为什么Java Jbutton没有正确调用JFileChooser?

为什么Java Jbutton没有正确调用JFileChooser?,java,swing,netbeans6.8,jfilechooser,Java,Swing,Netbeans6.8,Jfilechooser,以下代码是由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.

以下代码是由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

嗯……当我单击按钮时,我只得到一个空表单……知道bug在哪里吗?

JFileChooser本身并不像按钮那样是一个组件。这是一个对话。因此,这是工作“正确”。查看JFileChooser Java文档以了解如何使用JFileChooser。

JFileChooser本身并不像按钮那样是一个组件。这是一个对话。因此,这是工作“正确”。查看JFileChooser Java文档了解如何使用JFileChooser。

单击按钮时不应使用鼠标侦听器。您应该使用ActionListener


阅读JFileChooser API,并按照Swing教程中关于“如何使用文件选择器”的链接,获取如何显示文件选择器的工作示例。基本上,您的代码看起来与示例程序中ActionListener中的代码类似。

您不应该使用鼠标侦听器来单击按钮。您应该使用ActionListener

阅读JFileChooser API,并按照Swing教程中关于“如何使用文件选择器”的链接,获取如何显示文件选择器的工作示例。基本上,您的代码看起来与示例程序中ActionListener中的代码类似

 private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
fileBrowser fileBrowser = new fileBrowser();
fileBrowser.setVisible(true);//why not working?

}