Java Utililty Methods JTree

List of utility methods to do JTree

  1. HOME
  2. Java
  3. J
  4. JTree

Description

The list of methods to do JTree are organized into topic(s).

Method

void applyDefaultProperties(final JTree comp)
Sets default background and foreground color as well as a default font for the specified component.
if (comp == null) {
 return;
applyProperties(comp, "Tree.background", 
 "Tree.foreground", 
 "Tree.font"); 
void autoscroll(JTree tree, Point cursorLocation)
autoscroll
Insets insets = DEFAULT_INSETS;
Rectangle outer = tree.getVisibleRect();
Rectangle inner = new Rectangle(outer.x + insets.left, outer.y + insets.top,
 outer.width - (insets.left + insets.right), outer.height - (insets.top + insets.bottom));
if (!inner.contains(cursorLocation)) {
 Rectangle scrollRect = new Rectangle(cursorLocation.x - insets.left, cursorLocation.y - insets.top,
 insets.left + insets.right, insets.top + insets.bottom);
 tree.scrollRectToVisible(scrollRect);
...
boolean autoScrollIsDesirable(JTree tree)

Determines whether a tree should be in auto scroll mode.

boolean ret = false;
if (tree.getRowCount() < 1) {
 return ret;
Rectangle viewRect = tree.getVisibleRect();
int[] selected = tree.getSelectionRows();
boolean selectedIsVisible = false;
if (selected == null) {
...
void clearTreeIcon(JTree tree)
clear Tree Icon
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setOpenIcon(null);
renderer.setClosedIcon(null);
tree.setCellRenderer(renderer);
void correctRowHeight(JTree tree)
Update tree row height to the best possible considering font size changes on the current platform http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4760081
FontMetrics metrics = tree.getFontMetrics(tree.getFont());
tree.setRowHeight(Math.max(tree.getRowHeight(), metrics.getHeight()));
void disposeExpressionsTree()
dispose Expressions Tree
frame.dispose();
void enableAutoExpansion(final JTree tree)
Adds a TreeModelListener that will automatically expand the tree as new nodes are inserted.
tree.getModel().addTreeModelListener(new TreeModelListener() {
 public void treeNodesChanged(TreeModelEvent e) {
 public void treeNodesInserted(TreeModelEvent e) {
 tree.expandPath(e.getTreePath());
 public void treeNodesRemoved(TreeModelEvent e) {
 public void treeStructureChanged(TreeModelEvent e) {
});
TreePath findByName(JTree tree, String[] names)
find By Name
TreeNode root = (TreeNode) tree.getModel().getRoot();
return find2(tree, new TreePath(root), names, 0, true);
JTree findTree(Container container)
Traverse a container hierarchy and returns the first JMenuBar it finds.
Component[] components = container.getComponents();
for (Component component : components) {
 if (component instanceof JTree) {
 return (JTree) component;
 } else if (component instanceof Container) {
 JTree tree = findTree((Container) component);
 if (tree != null) {
 return tree;
...
int getCurrentWidth(JTree tree, int row)
get Current Width
return tree.getSize().width - 100;


AltStyle によって変換されたページ (->オリジナル) /