swing-util Module

JTree

dom2treeModel ( ( Document | InputStream | Reader | String | File | URL | org.xml.sax.InputSource ) input
{ , filterFunc(node), createFunc(node) } )
import javax.swing.*
frame = JFrame()
tree = JTree()
frame.contentPane.add(tree)

function namedMap(name, map){
   new java.util.HashMap(map){
     toString() {name}
   }
}
nodeAccess(true)
function createNode(node) {
  attr = node.attributes
  namedMap(attr.title, attr)
}
nodeAccess(false)

tree.model = dom2treeModel(opmlURL, function (n) n.tagName == "outline", createNode)
frame.pack()
frame.visible = true
traverseTreeNodes (TreeNode treeNode, enterFunc(treeNode), exitFunc(treeNode))

traverseTreeNodes() traverses nodes from the specified TreeNode in depth-first order.

expandTree(JTree tree)
collapseTree(JTree tree)

expandTree() expands all TreeNode.

collapseTree() collapses all TreeNode.

Message Dialog

showMessageDialog(String message) or
(Map map)
showConfirmDialog(String message) or
(Map map)
showInputDialog(String message) or
(Map map)
Key Value Remark
parentComponentParent component
messageMessage
titleTitle String
messageType
JOptionPane.ERROR_MESSAGE
JOptionPane.INFORMATION_MESSAGE
JOptionPane.WARNING_MESSAGE
JOptionPane.QUESTION_MESSAGE
JOptionPane.PLAIN_MESSAGE
iconIcon object
optionType
JOptionPane.YES_NO_OPTION
JOptionPane.YES_NO_CANCEL_OPTION
showConfirmDialog only
selectionValuesshowInputDialog only
initialSelectionValueshowInputDialog only

showMessageDialog("Message")
showInputDialog("Message")
showConfirmDialog("Message")

moveToCenter (componentOrWindow, frame)

Moves componentOrWindow to the center of frame.

Font

boldFont ( fontOrComponent )
plainFont ( fontOrComponent )
italicFont ( fontOrComponent )

Changes the font style of the specified Font or Component.

fontSize ( fontOrComponent , size )

Changes the font size of the specified Font or Component.

CellRenderer

jtree.cellRenderer = treeCellRenderer ( func(component, map) )
jlist.cellRenderer = listCellRenderer ( func(component, map) )
jcomboBox.renderer = listCellRenderer ( func(component, map) )
tableColumn.cellRenderer = tableCellRenderer ( func(component, map) )

Customizes cell rendering of JTree, JList, and JTable.

component is a Component object that represents the cell. The map parameter is a Map object of the following contents:

Key Value Remark
valuethe value associated with the cell
selectedselected or not
hasFocushas focus or not
expandednode is expanded or nottreeCellRenderer only
leafnode is a leaf or nottreeCellRenderer only
rowthe row numbertreeCellRenderer or tableCellRenderer
columnthe column numbertableCellRenderer only
indexthe row numberlistCellRenderer only

Selection

handleSelection (JTree tree, func(treeNode), boolean doubleClick)
(JList list, func(value), boolean doubleClick)
(JTable table, func(listSelectionEvent), boolean doubleClick)

If doubleClick is false, when selection is updated, func() is called.

If doubleClick is true, when a part of the specified component is double-clicked, func() is called.

Look&Feel

systemLookAndFeel ()

Specifies the system's look&feel.