4
最近提出的一个问题:How can I start the JFileChooser in the Details view?和answer为此提供了一种很好的技术。使用按日期排序的文件启动JFileChooser
我想在此提出的愿望一层:因为我现在知道如何打开JFileChooser中的详细信息视图,可我也让它使用日期排列的文件打开?我知道用户当然可以点击标题,但有没有办法在代码中实现这一点?
最近提出的一个问题:How can I start the JFileChooser in the Details view?和answer为此提供了一种很好的技术。使用按日期排序的文件启动JFileChooser
我想在此提出的愿望一层:因为我现在知道如何打开JFileChooser中的详细信息视图,可我也让它使用日期排列的文件打开?我知道用户当然可以点击标题,但有没有办法在代码中实现这一点?
我不知道有任何API来做到这一点。下面的代码通过查找文件选择器使用的表,然后手工做的那种日期列:
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);
您还需要达里尔的Swing Utils类。
+1 Nice hack;) – MadProgrammer 2013-05-07 23:54:55
非常好;谢谢。 – user1359010 2013-05-08 22:59:25