本文整理汇总了Java中javax.swing.JTree.getModel方法的典型用法代码示例。如果您正苦于以下问题:Java JTree.getModel方法的具体用法?Java JTree.getModel怎么用?Java JTree.getModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTree
的用法示例。
在下文中一共展示了JTree.getModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTreeCellRendererComponent
import javax.swing.JTree; //导入方法依赖的package包/类
public Component getTreeCellRendererComponent (
JTree tree, Object value,
boolean sel,
boolean expanded,
boolean leaf, int row,
boolean hasFocus
) {
JLabel l = (JLabel) super.getTreeCellRendererComponent (
tree, value, sel, expanded, leaf, row, hasFocus
);
if (value instanceof DefaultMutableTreeNode) {
l.setIcon (null);
l.setText ((String) ((DefaultMutableTreeNode) value).getUserObject ());
return l;
}
LanguagesNavigatorModel model = (LanguagesNavigatorModel) tree.getModel ();
l.setIcon (getCIcon (model.getIcon (value)));
l.setText (model.getDisplayName (value));
return l;
}
示例2: sortTree
import javax.swing.JTree; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public static void sortTree(PnlGuiConfig pnlGuiConfig, DefaultMutableTreeNode root, JTree treeTypes) {
if (root != null) {
Enumeration e = root.depthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
if (!node.isLeaf()) {
sort(node); //selection sort
}
}
//Atualizando a arvore
if (updateTree) {
TreePath treePath = treeTypes.getSelectionPath();
DefaultTreeModel model = (DefaultTreeModel) treeTypes.getModel();
model.reload();
treeTypes.setSelectionPath(treePath);
updateTree = false;
}
pnlGuiConfig.getPnlFieldCondition().ckDynamicClick();
}
}
示例3: getTreeCellRendererComponent
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
Component ret = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
SimulationTreeModel model = (SimulationTreeModel) tree.getModel();
if (ret instanceof JLabel) {
JLabel label = (JLabel) ret;
if (value instanceof SimulationTreeNode) {
SimulationTreeNode node = (SimulationTreeNode) value;
ComponentFactory factory = node.getComponentFactory();
if (factory != null) {
label.setIcon(new RendererIcon(factory, node.isCurrentView(model)));
}
}
}
return ret;
}
示例4: assertTreeModels
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Dumps the un-staged and stage models and asserts their content.
*
* @param unstagedExpected Expected for the un-staged model.
* @param indexExpected Expected for the staged model.
*/
protected void assertTreeModels(String unstagedExpected, String indexExpected) {
ChangesPanel unstagedChangesPanel = stagingPanel.getUnstagedChangesPanel();
JTree filesTable = unstagedChangesPanel.getTreeView();
StagingResourcesTreeModel uModel = (StagingResourcesTreeModel) filesTable.getModel();
// The newly created file is present in the model.
ChangesPanel stagedChangesPanel = stagingPanel.getStagedChangesPanel();
JTree stFilesTable = stagedChangesPanel.getTreeView();
StagingResourcesTreeModel stModel = (StagingResourcesTreeModel) stFilesTable.getModel();
// The newly created file is present in the model.
String ex = "--UNSTAGED--\n" + unstagedExpected + "\n\n--INDEX--\n" + indexExpected;
String ac = "--UNSTAGED--\n" + getTreeModelDump(uModel) + "\n\n--INDEX--\n" + getTreeModelDump(stModel);
assertEquals(ex, ac);
}
示例5: ExtendedCheckTreeMouseSelectionManager
import javax.swing.JTree; //导入方法依赖的package包/类
public ExtendedCheckTreeMouseSelectionManager(JTree tree, boolean selectAll) {
this.tree = tree;
selectionModel = new ExtendedCheckTreeSelectionModel(tree.getModel());
if (selectAll) {
selectionModel.addSelectionPath(tree.getPathForRow(0));
}
tree.setCellRenderer(new ExtendedCheckTreeCellRenderer(new DefaultTreeCellRenderer(), selectionModel));
tree.addMouseListener(this);
selectionModel.addTreeSelectionListener(this);
}
示例6: getPath
import javax.swing.JTree; //导入方法依赖的package包/类
private TreePath getPath(JTree tree, String path) {
String[] tokens = path.substring(1).split("(?<!\\\\)/");
TreeModel treeModel = tree.getModel();
if (treeModel == null) {
throw new RuntimeException("Could not find model for tree");
}
Object rootNode = treeModel.getRoot();
int start = tree.isRootVisible() ? 1 : 0;
TreePath treePath = new TreePath(rootNode);
StringBuilder searchedPath = new StringBuilder();
if (tree.isRootVisible()) {
String rootNodeText = unescapeSpecialCharacters(tokens[0]);
searchedPath.append("/" + rootNodeText);
assertTrue("JTree does not have a root node!", rootNode != null);
assertTrue("JTree root node does not match: Expected </" + getPathText(tree, treePath) + "> Actual: <"
+ searchedPath.toString() + ">", searchedPath.toString().equals("/" + getPathText(tree, treePath)));
}
for (int i = start; i < tokens.length; i++) {
String childText = unescapeSpecialCharacters(tokens[i]);
searchedPath.append("/" + childText);
boolean matched = false;
tree.expandPath(treePath);
for (int j = 0; j < treeModel.getChildCount(treePath.getLastPathComponent()); j++) {
Object child = treeModel.getChild(treePath.getLastPathComponent(), j);
TreePath childPath = treePath.pathByAddingChild(child);
if (childText.equals(getPathText(tree, childPath))) {
treePath = childPath;
matched = true;
break;
}
}
if (!matched) {
return null;
}
}
return treePath;
}
示例7: getContent
import javax.swing.JTree; //导入方法依赖的package包/类
public static String[][] getContent(JTree component) {
TreeModel model = component.getModel();
int rowCount = getNodeCount(model, model.getRoot()) + 1;
String[][] content = new String[1][rowCount];
List<String> treeContent = new Vector<String>(rowCount);
getTreeContent(model, model.getRoot(), treeContent);
treeContent.toArray(content[0]);
return content;
}
示例8: exportDone
import javax.swing.JTree; //导入方法依赖的package包/类
protected void exportDone(JComponent source, Transferable data, int action) {
if((action & MOVE) == MOVE) {
JTree tree = (JTree)source;
DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
// Remove nodes saved in nodesToRemove in createTransferable.
for(int i = 0; i < nodesToRemove.length; i++) {
model.removeNodeFromParent(nodesToRemove[i]);
}
}
}
示例9: importData
import javax.swing.JTree; //导入方法依赖的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;
}
示例10: exportDone
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
protected void exportDone(JComponent source, Transferable data, int action) {
if ((action & MOVE) == MOVE) {
JTree tree = (JTree) source;
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
// Remove nodes saved in nodesToRemove in createTransferable.
for (DefaultMutableTreeNode nodesToRemove1 : nodesToRemove) {
model.removeNodeFromParent(nodesToRemove1);
}
}
}
示例11: importData
import javax.swing.JTree; //导入方法依赖的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;
}
示例12: expandAll
import javax.swing.JTree; //导入方法依赖的package包/类
private void expandAll(JTree tree, TreePath path) {
tree.expandPath(path);
TreeModel model = tree.getModel();
Object lastComponent = path.getLastPathComponent();
for (int i = 0; i < model.getChildCount(lastComponent); i++) {
expandAll(tree,
path.pathByAddingChild(model.getChild(lastComponent, i)));
}
}
示例13: closePaths
import javax.swing.JTree; //导入方法依赖的package包/类
public void closePaths(JTree tree, TreePath path) {
Object node = path.getLastPathComponent();
TreeModel model = tree.getModel();
if (model.isLeaf(node))
return;
int num = model.getChildCount(node);
for (int i = 0; i < num; i++)
closePaths(tree, path.pathByAddingChild(model.getChild(node, i)));
tree.collapsePath(path);
}
示例14: closePaths
import javax.swing.JTree; //导入方法依赖的package包/类
public static void closePaths(JTree tree, TreePath path) {
Object node = path.getLastPathComponent();
TreeModel model = tree.getModel();
if (model.isLeaf(node))
return;
int num = model.getChildCount(node);
for (int i = 0; i < num; i++)
closePaths(tree, path.pathByAddingChild(model.getChild(node, i)));
tree.collapsePath(path);
}
示例15: browseRoot
import javax.swing.JTree; //导入方法依赖的package包/类
protected void browseRoot(JTree tree) {
TreeModel model = tree.getModel();
Object root = model.getRoot();
browseChildren(model, root, 0);
}