使用按日期排序的文件启动JFileChooser [英] Start a JFileChooser with files ordered by date

查看:288
本文介绍了使用按日期排序的文件启动JFileChooser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近有一个问题:如何在详细信息视图中启动JFileChooser ,而 answer 提供了一个很好的技巧。

A recent question asked: How can I start the JFileChooser in the Details view? and the answer provided a nice technique for doing that.

我想提高希望在这里一级:鉴于我现在知道如何在详细信息视图中打开JFileChooser,我可以还可以使用按日期排序的文件打开它吗?我知道用户当然可以点击标题,但是有没有办法在代码中发生这种情况?

I'd like to raise the aspiration here one level: given that I now know how to open the JFileChooser in details view, can I also get it to open with the files ordered by date? I know the user can of course click on the headings, but is there a way to make this happen in the code?

推荐答案

我不知道有什么API来做到这一点。以下代码查找文件选择器使用的表,然后手动对日期列进行排序:

I don't know of any API to do this. The following code finds the table used by the file chooser and then manually does the sort on the date column:

JFrame frame = new JFrame();
JFileChooser  fileChooser = new JFileChooser(".");
Action details = fileChooser.getActionMap().get("viewTypeDetails");
details.actionPerformed(null);

//  Find the JTable on the file chooser panel and manually do the sort

JTable table = SwingUtils.getDescendantsOfType(JTable.class, fileChooser).get(0);
table.getRowSorter().toggleSortOrder(3);

fileChooser.showOpenDialog(frame);

您还需要Darryl的 Swing Utils 类。

You will also need Darryl's Swing Utils class.

这篇关于使用按日期排序的文件启动JFileChooser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆