Breaking up Java Swing classes in Netbeans palette - java

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

Related

Java: Dynamic Layout using Eclipse Windowbuilder

I'm working on a Java project (for those curious, it's a Rcon and Query client for Minecraft servers) and I'm trying to create a GUI. I'm using Eclipse Windowbuilder, and I'm trying to make the program window dynamic (in other words, when the window is resized, everything else moves and scales to fit), but none of the layouts seem to do that (which defeats the purpose of the layout, doesn't it). It's worth mentioning that I'm putting four groups on the screen, which will contain other things and should take up all available space. I would put the code here, but there's nothing besides the default application framework generated by Eclipse. So, what layout do I use for dynamic resizing and such? Or am I missing something stupid?
(P.S. I've tried GridLayout, FormLayout, and many others. They didn't work.)
The following is for Eclipse Windowbuilder users.
For this to work (assuming GridLayout is used) you must set several properties for every single thing in the GridLayout:
grabExcessHorizontalSpace should be true (check the box)
grabExcessVerticalSpace should also be true (again, check the box)
horizontalAlignment should be set to FILL (selected from drop-down)
verticalAlignment should also be set to FILL (also selected from drop-down)
Thanks to greg-449 for giving me this link, which solved the problem.

How do you use a custom editor with the graphiti framework?

I've been doing research on this issue for two days now with no luck, I've looked at a couple of eclipse forum questions such as: http://www.eclipse.org/forums/index.php/t/441641/ which says to
subclass DiagramEditor
override that single method and create your behavior instance>
register your editor class with the org.eclipse.ui.editors extension point
(probably for your own diagram file extension)
My ultimate goal is to provide my own behavior and the way it's done according to what I've read in the documentation is to do the above, which I did. Here's a picture of how I added the extension point and used the class (which extends DiagramEditor) that I created.
But when I start it, it does not go through my editor, is there something I'm doing wrong or something else I also need to do?
As far as I can see on your screenshot, you have not set the extension. Add the extension of your model file to the 'extensions' block on the right. Then your editor will either become the default editor, or will be available in the Open with pop-up menu.

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.

File browser component for Java swing

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

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.

Categories