Introduction to Java Programming, Sixth Edition, Y. Daniel Liang

Chapter 31 JTable and JTree


Sections 31.2-31.7
1  You can create a JTable using __________.

A. new JTable()
B. new JTable(4, 5)
C. new JTable(new Integer[3][4], new Integer[4])
D. new JTable(new DefaultTableModel())

2  _________ are the properties in JTable.

A. gridColor
B. rowCount
C. columnCount
D. rowHeight
E. rowMargin

3  _________ are the properties in JTable.

A. showGrid
B. selectionMode
C. selectionBackground
D. selectionForeground
E. model

4  The autoResizeMode property specifies how columns are resized (you can resize table columns but not rows). Possible values are:

A. JTable.AUTO_RESIZE_OFF
B. JTable.AUTO_RESIZE_LAST_COLUMN
C. JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
D. JTable.AUTO_RESIZE_NEXT_COLUMN
E. JTable.AUTO_RESIZE_ALL_COLUMNS

5  The data in DefaultTableModel are stored in ___________.

A. an array
B. an ArrayList
C. a LinkedList
D. a Vector

6  DefaultTableModel contains the methods for

A. adding a new row
B. inserting a new row
C. adding a column
D. removing a row
E. removing a column

Sections 31.8-31.14
7  You can create a JTree using __________.

A. new JTree()
B. new JTree(new Object[]{"red", "green", "blue"})
C. new JTree(new Vector())
D. new JTree(new DefaultTreeModel())

8  Which of the following statements are true?

A. The TreeModel interface represents the entire tree. Unlike the ListModel or TableModel, the tree model does not directly store or manage tree data.
B. TreeModel contains the structural information about the tree, and tree data are stored and managed by TreeNode.
C. DefaultTreeModel is a concrete implementation for TreeModel that uses TreeNode.
D. To create a tree model, you may first create an instance of TreeNode to represent the root of the tree, and then create an instance of DefaultTreeModel fitted with the root.

9  To obtain a TreeModel from a JTree object, invoke ___________

A. getTreeModel()
B. getMode()
C. getDefaultTreeModel()
D. getTreeNode()

10  To make the JTree root visible, invoke ________________

A. setRootVisible(true)
B. setVisible(true)
C. setRootVisible(false)
D. setVisible(false)

11  To show the JTree root handles, invoke ________________

A. setShowsRootHandles(true)
B. setRootHandles(true)
C. setShowsRootHandles(false)
D. setRootHandles(false)

12  To obtain the root of a JTree, invoke ________________

A. getRoot()
B. getTreeRoot()
C. getRootNode()
D. getTreeRootNode()

13  To get the parent of a TreeNode, invoke ________________

A. getParentNode()
B. getParent()
C. getTreeParentNode()
D. getPreviousNode()

14  To get the first child of a TreeNode, invoke ________________

A. getAChild()
B. getFirstChild()
C. getLastChild()
D. getChild()

15  To get the depth of a JTree jTree, invoke ________________

A. jTree.getRoot().getDepth()
B. jTree.getDepth()
C. jTree.getTreeRoot().getDepth()
D. jTree.getRoot().getSize()

16  To insert a new child to a tree,

A. use the add method in JTree
B. use the add method in TreeNode
C. use the insert method in MutableTreeNode
D. use the insert method in TreeNode
E. use the insert method in JTree

17  To insert a new child to a tree,

A. use the add method in JTree
B. use the add method in TreeNode
C. use the insert method in MutableTreeNode
D. use the insert method in TreeNode
E. use the insert method in JTree

18  The getSelectionPath() method is defined in __________.

A. JTree
B. TreeNode
C. MutableTreeNode
D. TreeNode
E. TreeSelectionModel

19  To all the nodes in a TreePath, invoke _______________.
A. getNodes()
B. getPath()
C. getPathCount()
D. getParentPath()