2

I'm looking for a really simple widget: tree view on the left pane, folder contents on the right, switchable between icons, thumbnails, or detail view. Basically a functional (not pixel for pixel) emulation of Windows File Explorer, but within the Java app. How to do this using only built-in Java libraries? Or a very lightweight framework?

NOT A DUPLICATE

My question is different from the above and I now realize it's a little harder to explain than I initially expected. Two clarifications:

  1. My question is not about a File Chooser. I'm asking about a File Explorer type of dialog. The difference is that a File Chooser is really focused on one task, choosing a file. A File Explorer is a little less focused, and lets the user browse around without a clear objective.
  2. My question is not about native operating system UI / L&F emulation. At all. I'm asking about the basic capability to display the contents of the filesystem using icons and thumbnails. The style and borders etc are not part of my question.

EDIT

I'm looking for something like this enter image description here

Notice how it's different from this (JFileChooser) enter image description here

Alex R
  • 11,364
  • 15
  • 100
  • 180
  • 4
    Is there anything wrong with [`JFileChooser`](https://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html)? – MadProgrammer Dec 23 '15 at 21:21
  • I tried it and there was no treeview and no icons/thumbnails for folder contents – Alex R Dec 23 '15 at 21:38
  • There's nothing in the api that will do what you want, not with out a third party library, which is going to break the cross platform functionality – MadProgrammer Dec 23 '15 at 21:50
  • I see no reason why it should break cross-platform portability. I'm not looking for a pixel for pixel emulation. Just the basic functionality. – Alex R Dec 23 '15 at 21:53
  • The picture you added shows not JFileChooser. It shows the SWT FileDialog run in an old windows environment. – luksch Dec 23 '15 at 21:57
  • Possible duplicate of [Does Swing support Windows 7-style file choosers?](http://stackoverflow.com/questions/5703825/does-swing-support-windows-7-style-file-choosers) – luksch Dec 23 '15 at 22:00
  • @luksch This isn't a Windows 7 file chooser, it's a Windows 10 file chooser. – ThePyroEagle Dec 23 '15 at 22:03
  • Mostly because, that's not how a file browser looks on other platforms ;). – MadProgrammer Dec 23 '15 at 22:03
  • @ThePyroEagle the question is still very similar. It is not really important if you look at Win7 8 or 10 - the key point is that if the OP wants an OS-native File chooser or some look alike. – luksch Dec 23 '15 at 22:08
  • If you wanted a native solution, you could have a look at [this](http://stackoverflow.com/questions/6801242/calling-getopenfilename-through-jna-fails-for-swing-app) or [this](http://stackoverflow.com/questions/5703825/does-swing-support-windows-7-style-file-choosers), I've used [this](https://code.google.com/p/xfiledialog/) with moderate success or [this](https://github.com/steos/jnafilechooser/blob/master/api/src/main/java/jnafilechooser/api/JnaFileChooser.java) – MadProgrammer Dec 23 '15 at 23:19
  • I am NOT looking for a "OS-native File chooser or some look alike"... but really a function-alike – Alex R Dec 24 '15 at 00:31
  • 2
    Try [`FileBrowser`](http://codereview.stackexchange.com/q/4446/6692) or [`Outline`](http://codereview.stackexchange.com/a/4447/6692). – trashgod Dec 24 '15 at 04:25

3 Answers3

0

JFileChooser will do that if you are wanting something built in to Java.

https://docs.oracle.com/javase/7/docs/api/javax/swing/JFileChooser.html

Josh Chappelle
  • 1,558
  • 2
  • 15
  • 37
-1

If you are not using Swing but SWT (like Eclipse) you can use SWT FileDialog

luksch
  • 11,497
  • 6
  • 38
  • 53
  • also very different from File Explorer – Alex R Dec 23 '15 at 21:47
  • SWT FileDialog uses the standard dialog of your OS. In newer Windows systems it should look the way you expect it. I am not totally sure about this, since I am not using windows. – luksch Dec 23 '15 at 21:54
-1

You could use the AWT library to customly render the entirety of Explorer. Whilst the only hard part about this is correctly using layout managers to get components exactly where you want them and adding event listeners for each button, using AWT wouldn't make it look like Explorer on different operating systems because AWT uses the native system components.


You could check if the OS is not Windows and then use Swing if it isn't. In that case, you'd have to retexture every single used component such that its look and feel is the same as your targeted Windows version. Even if you did that, you'd still have to somehow change the JFrame's look and feel, which is possible using dark magic, but quite obscur. You can do this in a very quirky way, just setUndecorated(true) and manipulate the JFrame's boundaries until it lets you draw outside the JFrame, so that you can draw the Windows' decoration around it without resizing the Window. On top of that, you'd also have to check if it's maximised, as maximized windows don't quite look the same in Windows.


To cut things short, just use JFileChooser if you just want to allow the user to select one or multiple files. There isn't really any point in recreating Explorer, but if that's what you want to do, I'm not stopping you.

ThePyroEagle
  • 153
  • 12
  • I'm looking for basic functionality, an icon or thumbnail per file, with a tree view on the left. Not pixel for pixel clone. – Alex R Dec 23 '15 at 21:56
  • @AlexR Your question seemed to be asking for a pixel-for-pixel clone. I'll leave this answer for anyone who *wants* a clone, but if it doesn't suit you, **don't accept it**. – ThePyroEagle Dec 23 '15 at 22:00