本文整理汇总了Java中javax.swing.tree.DefaultTreeModel.insertNodeInto方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultTreeModel.insertNodeInto方法的具体用法?Java DefaultTreeModel.insertNodeInto怎么用?Java DefaultTreeModel.insertNodeInto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.DefaultTreeModel
的用法示例。
在下文中一共展示了DefaultTreeModel.insertNodeInto方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: refresh
import javax.swing.tree.DefaultTreeModel; //导入方法依赖的package包/类
private void refresh(DefaultTreeModel m,
ServerStatus.ModuleSummary[] modules) {
final MutableTreeNode root = (MutableTreeNode) m.getRoot();
totalPlayers = 0;
while (root.getChildCount() > 0) {
m.removeNodeFromParent((MutableTreeNode) root.getChildAt(0));
}
if (modules.length == 0) {
final DefaultMutableTreeNode n = new DefaultMutableTreeNode(
Resources.getString("Chat.no_connections")); //$NON-NLS-1$
n.setAllowsChildren(false);
}
else {
for (ServerStatus.ModuleSummary s : modules) {
m.insertNodeInto(createNode(s), root, root.getChildCount());
}
}
// append total number of players on server to root node
root.setUserObject(
Resources.getString(Resources.VASSAL) + " (" + totalPlayers + ")");
}
示例2: sortNodesDescending
import javax.swing.tree.DefaultTreeModel; //导入方法依赖的package包/类
/**
* Sort nodes descending.
*
* @param node the node
* @param treeModel the tree model
*/
private void sortNodesDescending(DefaultMutableTreeNode node, DefaultTreeModel treeModel) {
boolean unsorted = true;
while (unsorted) {
unsorted = false;
for (int i = 0; i < node.getChildCount() - 1; i++) {
ThreadInfoStorageAgent tiaFirst = (ThreadInfoStorageAgent) ((DefaultMutableTreeNode) node.getChildAt(i)).getUserObject();
ThreadInfoStorageAgent tiaSecond = (ThreadInfoStorageAgent) ((DefaultMutableTreeNode) node.getChildAt(i+1)).getUserObject();
if (tiaFirst.getXYSeriesMap().get("TOTAL_CPU_SYSTEM_TIME").getMaxY() < tiaSecond.getXYSeriesMap().get("TOTAL_CPU_SYSTEM_TIME").getMaxY()) {
treeModel.insertNodeInto((MutableTreeNode) node.getChildAt(i+1), node, i);
unsorted = true;
}
}
}
}
示例3: importData
import javax.swing.tree.DefaultTreeModel; //导入方法依赖的package包/类
@Override
public boolean importData(TransferHandler.TransferSupport transferSupport) {
if (!canImport(transferSupport)) {
return false;
}
try {
DefaultMutableTreeNode[] nodes = (DefaultMutableTreeNode[]) transferSupport.getTransferable().getTransferData(myDataFlavor);
JTree.DropLocation dropLocation = (JTree.DropLocation) transferSupport.getDropLocation();
int index = dropLocation.getChildIndex();
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) dropLocation.getPath().getLastPathComponent();
DefaultTreeModel model = (DefaultTreeModel) ((JTree) transferSupport.getComponent()).getModel();
for (int i = 0; i < nodes.length; i++) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode) nodes[i].getUserObject();
model.insertNodeInto(child, parent, index);
insertNodeInto(parent, index, child);
}
onTransferDone();
} catch (UnsupportedFlavorException e1) {
log("[WARN] UnsupportedFlavor: " + e1.getMessage());
} catch (java.io.IOException e2) {
log("[WARN] I/O error: " + e2.getMessage());
}
return true;
}
示例4: run
import javax.swing.tree.DefaultTreeModel; //导入方法依赖的package包/类
@Override
public void run() {
Thread.currentThread().setUncaughtExceptionHandler(this);
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
DefaultTreeModel model = new DefaultTreeModel(root);
this.tree = new JTree();
this.tree.setModel(model);
JFrame frame = new JFrame(getClass().getSimpleName());
frame.add(this.tree);
model.addTreeModelListener(this); // frame is not visible yet
model.insertNodeInto(child, root, root.getChildCount());
model.removeNodeFromParent(child);
frame.setSize(640, 480);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
示例5: importData
import javax.swing.tree.DefaultTreeModel; //导入方法依赖的package包/类
public boolean importData(TransferHandler.TransferSupport support) {
if(!canImport(support)) {
return false;
}
// Extract transfer data.
DefaultMutableTreeNode[] nodes = null;
try {
Transferable t = support.getTransferable();
nodes = (DefaultMutableTreeNode[])t.getTransferData(nodesFlavor);
} catch(UnsupportedFlavorException ufe) {
System.out.println("UnsupportedFlavor: " + ufe.getMessage());
} catch(java.io.IOException ioe) {
System.out.println("I/O error: " + ioe.getMessage());
}
// Get drop location info.
JTree.DropLocation dl =
(JTree.DropLocation)support.getDropLocation();
int childIndex = dl.getChildIndex();
TreePath dest = dl.getPath();
DefaultMutableTreeNode parent =
(DefaultMutableTreeNode)dest.getLastPathComponent();
JTree tree = (JTree)support.getComponent();
DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
// Configure for drop mode.
int index = childIndex; // DropMode.INSERT
if(childIndex == -1) { // DropMode.ON
index = parent.getChildCount();
}
// Add data to model.
for(int i = 0; i < nodes.length; i++) {
model.insertNodeInto(nodes[i], parent, index++);
}
return true;
}
示例6: importData
import javax.swing.tree.DefaultTreeModel; //导入方法依赖的package包/类
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
// Extract transfer data.
DefaultMutableTreeNode[] nodes = null;
try {
Transferable t = support.getTransferable();
nodes = (DefaultMutableTreeNode[]) t.getTransferData(nodesFlavor);
} catch (UnsupportedFlavorException ufe) {
System.out.println("UnsupportedFlavor: " + ufe.getMessage());
} catch (java.io.IOException ioe) {
System.out.println("I/O error: " + ioe.getMessage());
}
// Get drop location info.
JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
int childIndex = dl.getChildIndex();
TreePath dest = dl.getPath();
DefaultMutableTreeNode parent = (DefaultMutableTreeNode)
dest.getLastPathComponent();
JTree tree = (JTree) support.getComponent();
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
// Configure for drop mode.
int index = childIndex; // DropMode.INSERT
if (childIndex == -1) { // DropMode.ON
index = parent.getChildCount();
}
// Add data to model.
for (DefaultMutableTreeNode node : nodes) {
model.insertNodeInto(node, parent, index++);
}
return true;
}