File browser component for Java swing - java

Has anyone come across a fully customizable (compatible with all standard LnF), fast file browser component for Java Swing ?
I should be able to place this component to Netbeans UI palette and drag and drop in to any JPanel while designing the UI. Also it should support directory, single file, multiple file selection along with file type filtering.
There must be something because I have seen this in applications like jEdit etc.
Note that I am not asking about a dialog box like JFileChooser instead a browser/explorer/tree-view like component.

Here's a relatively simple file system browser built in a JPanel:
File Tree
Here are a few more complex examples of a file browser with icons, popup menus, and tooltips.
These are all built in a JFrame:
File Tree with Icons
File Tree with Popup Menu
File Tree with Tooltips
These examples probably aren't as customizable as you may want, but they're a pretty good
starting point for adding new functionality.
For further reading, Swing, Second Edition (Chapter 17) walks through implementing a JTree component for browsing your file system complete with lazy loading, custom renders, popup menus, and tooltips.
If you'd like to see just the source, you can get it here.
There is also the FileBro that you may want to take a look at. Perhaps you can use it, or at least borrow implementation details.
FileBro

see DJ Project:
http://djproject.sourceforge.net/ns/index.html

Related

How should I efficiently update a Swing GUI?

I created a program with a Swing GUI in NetBeans a while back using the Graphical Editor. I now needed a web version but since I use eclipse now I copied + pasted the code into a new Web Applet project. I found some problems I didn't spot before and updated the code in the web applet.
I want to add some buttons to the GUI, but one problem is its an annoyance to find the part of the code where NetBeans put all the variable declarations, then find another part of the code where all the fields are initialised, then find the other part of the code where the layout needs to be defined, then find the other part of the code where all the action listeners are added, etc... Another problem is that the Swing layouts are complex and also an annoyance to hard code... it is difficult to judge what the exact outcome will look like when you have to edit GroupLayouts with other swing components already layed out in them.
Also, I can't edit this in NetBeans because the Generator is very fussy and if I copy+paste code in there it wont read it as a Java Form nor generate an XML file which I think it uses to manage your layout.
Are there any free GUI designers out there that take a bunch of java swing code and allow you to graphically edit it? How do professionals manage their graphical layouts?
So I should have implemented the Model-View approach from the start.
Here is a nice tutorial on the subject:
http://people.csail.mit.edu/phw/OnToJava/ONTOJAVA755.HTML

How does Eclipse know whether the Swing Designer is available for a JFrame-derived class?

I am using Google Web Toolkit's Swing Designer in Eclipse to create and edit components like custom JFrame's.
The problem is that the Design View is sometimes broken for my class (probably because the project is also being edited by another person in a different platform), and I want to know how to restore it. In other words, I am able to edit the code for a custom JFrame, but I cannot use the visual editor to modify the JFrame anymore. I notice that the icon for my JFrame's source code also changes to a normal java-source-code icon when the design view is broken.
In which file does Eclipse keep track of what JFrame's can be edited using the visual editor and which ones not?
Thanks in advance.
If you want to open a file in the designer, but that's not happening by default, then use right-click Open With>WindowBuilder Editor.
If you don't see the Design tab, that means that you are just using the standard Eclipse Java Editor rather than the WindowBuilder editor. Eclipse allows you to use different editors via the Open With command. This is very basic Eclipse behavior, so it is something you should learn about. This is also covered in the WB docs and FAQ.

Seek a Java advanced tree component (include Windowless Richedit Control function)

I love BooguNote very much (it's a Sharp tool for collecting and organizing information scraps) But what a pity it just run under windows currently.
I tried to build a Java version for BooguNote so I can run it under linux (first step: I want to just make a simple BooguViewer ) since I'm not very familiar with so huge Java libraries, so I ask for help who know the suitable Java tree component in this case.
My requirement is this:
it's not an usual tree component, as you can check from the BooguNote's screenshot as below:
http://boogu.me/en.jpg
Usual tree is used as an outline, but in BooguNote, tree node was used as a content container at the same time - you can even save a huge text in it! (I heard the author said in the forum before he used "Windowless Richedit Control" technology).
Any advices are welcome, Thanks in advance.
This Oracle tutorial tells you how to create graphical user interfaces (GUIs) for applications and applets, using the Java Swing components.
Start with the Using Swing Components tutorial. Go through the following top-level lessons:
Using Top-Level Containers
The JComponent Class
Using Text Components
Go through the following component lessons:
How to Make Frames (Main Windows)
How to Use Panels
How to Use Trees
The Swing components that you want to use to make a viewer are JFrame, JPanel, and JTree.

Breaking up Java Swing classes in Netbeans palette

I would like to know the best method of breaking up large Java Swing classes. Some of mine are quite large and I would like to begin the process of properly modularizing my code. I saw that I could add my classes to Netbeans' palette but the problem is they are not showing me a graphical representation of what it will look like when I "drop" them into the GUI designer. Some third party jar files support getting added to the palette and they provide a graphical preview of what they'll look like once run.
My question is, I don't know the proper terminology for what this "preview" is called so I'm finding it very difficult to search for. I would like some documentation or a tutorial on how to make my current classes able to be added to the palette and see what it is they will look like in the GUI designer.
Thank you!
To get an icon, you need to provide a BeanInfo for you class.
The easiest way to do this is right click on the class in the Project window and select BeanInfo editor....
You'll want to switch to the designer view to configure which properties are expert/hidden/preferred.
Preferred properties appear in the top most fold (Properties) of the Property window.
Expert properties appear in the second fold (Other Properties).
Hidden do not appear at all.
You can also specify whether properties are bound, constrained, etc. To set icons, choose the topmost node of the tree (BeanInfo) and you'll see properties for the icons.
To make NetBeans treat your component as a container (or not a container):
Switch to Source view
Find the line reading
// Here you can add code for customizing the BeanDescriptor.
Add this line:
beanDescriptor.setValue("isContainer", Boolean.TRUE); // Or FALSE if it's not a container

DragNDrop from Java to Windows Explorer

I want to create an application in Java that lists a directory and add drag and drop support to it for copying files from that directory to the explorer window opened and vice-versa(Windows system).
While adding support to drag and drop from windows explorer to the java application is quite easy, it kind of eludes me how to do it when the action starts from the java application and ends in explorer.
I tried searching google and SO, but to no avail.
Any pointers, directions, snippets of codes or pseudocodes will be appreciated.
So, is it possible to drag from a java application and transfer data to a drop target in a native application? If yes (it should be), can you point me in the right direction?
Yes, what you have to do is set the mime type on the transferable, and set the accepted actions (i.e. copy, move, etc) as well as the default action (it sounds like a copy action for what you are trying to do). This class is the transfer handler, which is what is used to handle DnD in Swing.
Just use the fileListFlavour DataFlavour and File drag'n drop will "just work" in both directions.
I'm sure you found the section on drag n drop in the java tutorial.
Book: Swing Hacks
Hack # 65
That's your answer :)

Categories