Run JFileChooser with files sorted by date

Recent Question: How can I run JFileChooser in the Details view? and subject to good technique for this.

I would like to raise my aspiration one level: given that now I know how to open JFileChooser in a detailed view, can I also open it with files sorted by date? I know that the user can, of course, click on the headers, but is there a way to do this in the code?

+4
source share
1 answer

I do not know any API for this. The following code finds the table used by file selection, and then manually sorts it by 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); 

You will also need the Darryl Swing Utils class.

+6
source

Source: https://habr.com/ru/post/1479636/


All Articles