Hice una pequeña prueba con un boton que llama al selector y una etiqueta y funciona todo OK.
Código Java:
Ver original/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication14;
import java.io.File;
import javafx.stage.FileChooser;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
*
* @author juanjo
*/
public class NewJFrame
extends javax.
swing.
JFrame {
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
jLabel1.setText("");
}
/**
* 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() {
jLabel1
= new javax.
swing.
JLabel(); jButton1
= new javax.
swing.
JButton();
jLabel1.setText("jLabel1<P>Prueba");
jButton1.setText("jButton1");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) { jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)))
.
addContainerGap(288,
Short.
MAX_VALUE)) );
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)
.
addContainerGap(231,
Short.
MAX_VALUE)) );
pack();
}// </editor-fold>
private void jButton1ActionPerformed
(java.
awt.
event.
ActionEvent evt
) { // TODO add your handling code here:
jf.setFileFilter(new FileNameExtensionFilter("todos los archivos *.CSV", "csv","CSV"));
int abrir = jf.showDialog(null, "Abrir");
File archivo
= jf.
getSelectedFile(); jLabel1.setText(jLabel1.getText()+"<HTML>"+archivo.getName()+"<P>");
}
}
/**
* @param args the command line arguments
*/
public static void main
(String args
[]) { /* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
if ("Nimbus".equals(info.getName())) {
javax.
swing.
UIManager.
setLookAndFeel(info.
getClassName()); break;
}
}
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.
swing.
JButton jButton1
; private javax.
swing.
JLabel jLabel1
; // End of variables declaration
}