1.使窗体位于屏幕中心
Dimension welcomeScreen=Toolkit.getDefaultToolkit().getScreenSize(); int x=(welcomeScreen.width-this.getSize().width)/2; int y=(welcomeScreen.height-this.getSize().height)/2; this.setBounds(x, y, 500, 400);
2.设置文件过滤器
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jFileChooser1.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".txt")||f.isDirectory(); //To change body of generated methods, choose Tools | Templates. } @Override public String getDescription() { return ".txt 文件"; //To change body of generated methods, choose Tools | Templates. } }); jFileChooser1.showOpenDialog(this); }
时间: 2024-12-05 02:40:52