java - 为什么 Java Jbutton 没有正确调用 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.
 * 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/

相关文章:

java - 将输出写入文本文件

java - 在android中使用简单的java类进行Facebook native 登录

java - 无法理解 Comparable<T> 转换

java - 图像未加载到框架中

java - 如何将 JFrame 放入 Java Swing 中现有的 JPanel 中?

java - 为 Ibatis 加密一个属性文件

netbeans - 在选项卡中显示文件名的完整路径 ~ Netbeans 6.8

java - 方法没有采用正确的数组

java - 我应该使用什么组件在 Java 中绘制树状图?

java - 如何使用 Java 和 NetBeans 将数据显示为图像