没时间细调了,自己调去吧 package com.syj;import java.awt.BorderLayout; import java.awt.Font; import java.io.File;import javax.swing.JButton;import javax.swing.JFileChooser; import javax.swing.WindowConstants; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileFilter;/** * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI * Builder, which is free for non-commercial use. If Jigloo is being used * commercially (ie, by a corporation, company or business for any purpose * whatever) then you should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. Use of Jigloo implies * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR * ANY CORPORATE OR COMMERCIAL PURPOSE. */ public class NewJFrame extends javax.swing.JFrame { private JButton jButton1; /** * Auto-generated main method to display this JFrame */ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { NewJFrame inst = new NewJFrame(); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); } public NewJFrame() { super(); initGUI(); } private void initGUI() { try { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jButton1 = new JButton(); getContentPane().add(jButton1, BorderLayout.CENTER); jButton1.setText("jButton1"); } jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setApproveButtonText("选择"); chooser.setFont(new Font("宋体", Font.PLAIN, 14)); chooser .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { String filePath = f.getAbsoluteFile().toString() .toUpperCase(); if (filePath.endsWith("BMP") || filePath.endsWith("JPG")) return true; else return false; } public String getDescription() { return null; } }); int returnVal = chooser.showOpenDialog(getContentPane()); if (returnVal == JFileChooser.APPROVE_OPTION) { String temp = String.valueOf(chooser.getSelectedFile()); System.out.println(temp); } } }); pack(); setSize(400, 300); } catch (Exception e) { e.printStackTrace(); } }}
package com.syj;import java.awt.BorderLayout;
import java.awt.Font;
import java.io.File;import javax.swing.JButton;import javax.swing.JFileChooser;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter;/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class NewJFrame extends javax.swing.JFrame {
private JButton jButton1; /**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
NewJFrame inst = new NewJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
} public NewJFrame() {
super();
initGUI();
} private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jButton1 = new JButton();
getContentPane().add(jButton1, BorderLayout.CENTER);
jButton1.setText("jButton1");
}
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setApproveButtonText("选择");
chooser.setFont(new Font("宋体", Font.PLAIN, 14));
chooser
.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
String filePath = f.getAbsoluteFile().toString()
.toUpperCase();
if (filePath.endsWith("BMP")
|| filePath.endsWith("JPG"))
return true;
else
return false;
} public String getDescription() {
return null;
}
});
int returnVal = chooser.showOpenDialog(getContentPane());
if (returnVal == JFileChooser.APPROVE_OPTION) {
String temp = String.valueOf(chooser.getSelectedFile());
System.out.println(temp);
}
}
});
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}}
public boolean accept(File f) {
String filePath = f.getAbsoluteFile().toString()
.toUpperCase();
if (filePath.endsWith("BMP")
|| filePath.endsWith("JPG"))
return true;
else
return false;
} public String getDescription() {
return "aaa";
}
});