Skip to main content

Using JTree to Show the Forest: Hierarchical Relationships of Components

  • Chapter
  • First Online:
Swing for Jython
  • 888 Accesses

Abstract

This chapter is all about building and using trees to display a hierarchical relationship between elements. Trees allow you to convey a specific relationship between different pieces of information. For example, this kind of structure is great for showing something like an organizational chart. By the time you’re through with this chapter, you should not only be able to use trees in your own applications, but you will also more aware of the capabilities and limitations of this useful structure.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 44.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 59.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/JTree.html .

  2. 2.

    To minimize the chance of confusion, I’m going to try to be consistent and refer to Swing tree nodes as nodes, and WebSphere Application Server nodes as WebSphere nodes.

  3. 3.

    This topic also came up in Chapter 10.

  4. 4.

    Tree nodes can be expanded or collapsed by positioning the entry using a mouse or cursor keys and pressing Enter.

  5. 5.

    Remember that AdminConfig is a wsadmin scripting object, and therefore is only available when wsadmin is used to execute the Jython script.

  6. 6.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/tree/DefaultMutableTreeNode.html .

  7. 7.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/tree/TreeModel.html .

  8. 8.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/tree/DefaultTreeModel.html .

  9. 9.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/tree/TreeSelectionModel.html .

  10. 10.

    See the section in Chapter 9 entitled “Limiting the Selectable Items.”

  11. 11.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/event/TreeSelectionListener.html .

  12. 12.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/event/ListSelectionListener.html .

  13. 13.

    The dataType of the value returned by the getLastSelectedPathComponent() method call is an object, so it needs to be converted to a string before this value can be used to update the JTextField value.

  14. 14.

    This example is based on the DynamicTreeDemo from the Java Swing Tutorial, which can be found at http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html#dynamic .

  15. 15.

    See http://docs.oracle.com/javase/8/docs/api/java/awt/Window.html#setLocationRelativeTo%28java.awt.Component%29 .

  16. 16.

    Actually, the top-left corner of the application is positioned on the center of the screen. This should be “close enough” for now.

  17. 17.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/tree/DefaultTreeModel.html .

  18. 18.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/event/TreeModelListener.html .

  19. 19.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/event/TreeModelEvent.html .

  20. 20.

    It’s interesting to note that the specified node is expanded or collapsed as part of the normal double-click process. That’s why the tree is collapsed as part of this edit process.

  21. 21.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/tree/DefaultTreeCellEditor.html .

  22. 22.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/tree/DefaultTreeCellRenderer.html .

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2015 Robert A. Gibson

About this chapter

Cite this chapter

Gibson, R.A. (2015). Using JTree to Show the Forest: Hierarchical Relationships of Components. In: Swing for Jython. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0817-5_11

Download citation

Publish with us

Policies and ethics