use*_*010 4 java swing jfilechooser date
最近提出的一个问题是:如何在详细信息视图中启动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);
Run Code Online (Sandbox Code Playgroud)
您还需要Darryl的Swing Utils课程.