java+getactionmap,registerKeyboardAction(...)和getInputMap().put(...)+ getActionMap().put(...)有什么区别?...

What is the difference between these two methods:

getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(

"pressed F10"), "someAction");

getActionMap().put("someAction", new AbstractAction() {

@Override

public void actionPerformed(ActionEvent e) {

//Do something

}

});

and:

registerKeyboardAction(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

//Do something

}

}, KeyStroke.getKeyStroke("pressed F10"), JComponent.WHEN_FOCUSED);

解决方案

There is no difference, but registerKeyboardAction is obsolete as stated in the javadoc.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
FileSystemView fileSystemView=FileSystemView.getFileSystemView(); File tempFile; if (filepath==null||filepath.isEmpty()||filepath.equals("")) { tempFile=fileSystemView.getHomeDirectory(); }else { tempFile=new File(filepath); } JFileChooser chooser = new JFileChooser(tempFile); //设置选择器 chooser.setMultiSelectionEnabled(true); //设为多选 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);//设置可选择的为文件和文件夹 chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() { @Override public String getDescription() { // TODO Auto-generated method stub return ".xml"; } @Override public boolean accept(File f) { // TODO Auto-generated method stub if (f.getName().toLowerCase().endsWith(".xml")) { return true; } return false; } }); chooser.setDialogTitle("请选择需要修改的文件"); chooser.setPreferredSize(new Dimension(800,1000)); chooser.getActionMap().get("viewTypeDetails").actionPerformed(null); chooser.showOpenDialog(button); //显示打开文件选择框 filepath = chooser.getSelectedFile().getAbsolutePath(); //获取绝对路径 button.setText(filepath); if (chooser.isFileSelectionEnabled()) { new MyJOptionPane("目前仅支持修改xml格式文件,请选择正确的格式"); } if(chooser.isDirectorySelectionEnabled()) { progressBar.setIndeterminate(true); progressBar.setStringPainted(false); progressDialog.setVisible(true); Thread thread=new Thread(() -> { try { XmlHanding.getMyFlie(new File(filepath)); text.setText("已选择文件夹:"+filepath); text.append("\n"+"文件包含"+XmlHanding.fList.size()+"个xml文件"); for(File f:XmlHanding.fList){ text1.append("\n"+f.getAbsolutePath()); } text1.setCaretPosition(0); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); }finally { // 执行完毕后关闭进度对话框 progressDialog.dispose(); } }); thread.start(); } }为什么选择了单个的文件 text还是会写入"已选择文件夹:"+filepath
最新发布
07-15

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值