JTree node incorrectly becomes a leaf after collapse?
Hi all,
I'm trying to fix a bug in a JTree where a node spuriously turns into a leaf after the user collapses it, and I'm beginning to wonder whether it's my code that's at fault or something within Java (The project uses JDK 1.3.1.06 - I cannot change this part!)
The problem is as follows. The user expands the tree and selects a leaf. He or she then clicks the collapse icon of a node somewhere in the path to that leaf. (that node can be the parent, grandparent, great-grandparent or any other node, right up to the root.) The node collapses, but the expand icon is not displayed beside the collapsed node, and double-clicking does not cause the node to expand. In other words, the node now looks like a leaf.
The problem does not occur if the user collapses the node by double-clicking on the node, or if an non-leaf node was selected.
My swing knowledge is not that extensive, so I was wondering whether this was a known bug, or whether anyone can think of some obvious mistake I might be making...
/Michael
HI,
Is the node which is becoming leaf do have some childrens?
If not than checkout while creating object of DefaultMutableTreeNode did u specified have its allowsChildren property to false.
In case your case is different from above. Than you might have encountered some bug in JTree, which you can report at following URI.
http://java.sun.com/webapps/bugreport/
Cheers
-Hemant
Similar Messages
-
Jtree node refuses to collapse upon clicking handle; makeVisible() was used
Hello,
While creating a new node and inserting as a leaf in the JTree, I use tree.makeVisible(newTreePath) to expand the new node and make visible. (Using expandPath() will not expand if a leaf was added).
However now the jtree node refuses to collapse upon clicking the node handle.
How do I get it to not insist on staying open - be able to collapse manually?
thanks,
AnilThis is the JNI forum. I don't believe your post fits.
then
can I correctly assume that any class that
"implements Cloneable" will handle making either a
"shallow" or "deep" ... or even "semi-shallow" clone,
respective to the class context .. right?
It probably does something. The implementor might not have implemented anything though. And you have no idea what they implemented.
No idea about your other question.
You might want to think carefully about why you are cloning though. -
Ise node not becoming standalone after deregistration
I am seeing a weird problem.
I deregistered secondary admin/monitor node from primary admin/monitor node. I see successfully deregistered message.
But the deregistered node is still showing SEC(A) and SEC(M). It is not changing to standalone mode.
This is disrupting the upgrade of distributed deployment of ISE nodes.
Any clues?Bug details:
Secondary node never becomes standalone after de-registration
The secondary node is de-registered successfully but a "The following deregistered nodes are not currently reachable: . Be sure to reset the configuration on these nodes manually, as they may not revert to Standalone on their own." message appears to the administrator.
Workaround Log in to the administrator user interface with internal Cisco ISE administrator credentials when de-registering a node.
Actually we had two accounts in web gui, nodes were registered using one account and during upgrade, i used different account , which triggered this bug. -
Restricting Jtree node from collapsing.
Hi all,
Is there any way by which i can restrict a Jtree node from collapsing?
please help,
thx,
Soni.hi
i got it,
here is the solution
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
public void treeWillExpand(TreeExpansionEvent e)throws ExpandVetoException {
public void treeWillCollapse(TreeExpansionEvent e)throws ExpandVetoException {
TreePath p = e.getPath();
DefaultMutableTreeNode n =
(DefaultMutableTreeNode)p.getLastPathComponent();
if (n == root) {
throw new ExpandVetoException(e);
-Soni -
Parse and display xml doc when click on JTree node?
Ok so here is the code that I have now. You will have to make alot of html files to run the program, but they can be empty for now. What you can do is just put the same exact html file to be displayed in each node element. for example.
DefaultMutableTreeNode n1_node1_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Device", "device.html"));could be changed to
DefaultMutableTreeNode n1_node1_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Device", "status.html"));And just keep adding the status.html page to each one of the nodes.
anyway.
For now when I click on the node, the html file is displayed in the JScrollPane rPane = new JScrollPane(htmlPane); and the htmlPane is a JEditorPane
what I need it to do.
When I click on the JTree node. I would like to go out to an xml file, parse the information in it, and display it to the pane.
I will need to later, be able to add, edit, or delete information on the xml through the pane later.
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.JTree;
import javax.swing.JPanel;
import javax.accessibility.*;
import javax.swing.UIManager;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.ImageIcon;
import java.net.URL;
import java.io.IOException;
import java.awt.Dimension;
* @author orozcom
public class Example extends JFrame implements TreeSelectionListener
private JEditorPane htmlPane;
private URL helpURL;
private static boolean DEBUG = false;
private JTree tree;
public Example()
super("Example");
setSize(1200,900);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JMenuBar jmb = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem openItem = new JMenuItem("Open");
JMenuItem saveItem = new JMenuItem("Save");
JMenuItem exitItem = new JMenuItem("Exit");
exitItem.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
System.exit(0);
fileMenu.add(openItem);
fileMenu.add(saveItem);
fileMenu.add(new JSeparator());
fileMenu.add(exitItem);
jmb.add(fileMenu);
setJMenuBar(jmb);
// **************** start JTree ******************//
JPanel lPane =new JPanel();
lPane.setLayout(new BorderLayout());
DefaultMutableTreeNode top = new DefaultMutableTreeNode(new ModuleInfo("Devices","splashScreen.html"));
DefaultMutableTreeNode branch1 =
new DefaultMutableTreeNode(new ModuleInfo("Module 1", "module1.html"));
DefaultMutableTreeNode branch2 =
new DefaultMutableTreeNode(new ModuleInfo("Module 2", "module2.html"));
//DefaultMutableTreeNode branch3 =
//new DefaultMutableTreeNode(new ModuleInfo("Module 3", "module3.html"));
//adding to the topmost node
top.add(branch1);
top.add(branch2);
//top.add(branch3);
* BRANCH 1 *
//adding to the First branch
DefaultMutableTreeNode node1_b1
=new DefaultMutableTreeNode(new ModuleInfo("Status", "status.html"));
//branch1.add(node1_b1);
DefaultMutableTreeNode n1_node1_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Device", "device.html"));
DefaultMutableTreeNode n2_node1_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Network", "network.html"));
DefaultMutableTreeNode n3_node1_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Chassis", "chassis.html"));
DefaultMutableTreeNode n4_node1_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Resources", "resources.html"));
node1_b1.add(n1_node1_b1);
node1_b1.add(n2_node1_b1);
node1_b1.add(n3_node1_b1);
node1_b1.add(n4_node1_b1);
DefaultMutableTreeNode node2_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Project Editor", "projedit.html"));
DefaultMutableTreeNode node3_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Project Manager", "projmngt.html"));
DefaultMutableTreeNode node4_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Administration", "administration.html"));
DefaultMutableTreeNode n1_node4_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Device", "device.html"));
DefaultMutableTreeNode n2_node4_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Network", "network.html"));
DefaultMutableTreeNode n3_node4_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Users", "users.html"));
node4_b1.add(n1_node4_b1);
node4_b1.add(n2_node4_b1);
node4_b1.add(n3_node4_b1);
DefaultMutableTreeNode node5_b1 =
new DefaultMutableTreeNode(new ModuleInfo("Logging", "logging.html"));
branch1.add(node1_b1);
branch1.add(node2_b1);
branch1.add(node3_b1);
branch1.add(node4_b1);
branch1.add(node5_b1);
* BRANCH 2 *
//adding to the Second branch
DefaultMutableTreeNode node1_b2 =
new DefaultMutableTreeNode(new ModuleInfo("Status", "status.html"));
DefaultMutableTreeNode n1_node1_b2 =
new DefaultMutableTreeNode(new ModuleInfo("Device", "device.html"));
DefaultMutableTreeNode n2_node1_b2 =
new DefaultMutableTreeNode(new ModuleInfo("Network", "network.html"));
DefaultMutableTreeNode n3_node1_b2 =
new DefaultMutableTreeNode(new ModuleInfo("Chassis", "chassis.html"));
DefaultMutableTreeNode n4_node1_b2 =
new DefaultMutableTreeNode(new ModuleInfo("Resources", "resources.html"));
node1_b2.add(n1_node1_b2);
node1_b2.add(n2_node1_b2);
node1_b2.add(n3_node1_b2);
node1_b2.add(n4_node1_b2);
DefaultMutableTreeNode node2_b2=
new DefaultMutableTreeNode(new ModuleInfo("Project Editor", "projedit.html"));
DefaultMutableTreeNode node3_b2=
new DefaultMutableTreeNode(new ModuleInfo("Project Manager", "projmngt.html"));
DefaultMutableTreeNode node4_b2=
new DefaultMutableTreeNode(new ModuleInfo("Administration", "administration.html"));
DefaultMutableTreeNode n1_node4_b2=
new DefaultMutableTreeNode(new ModuleInfo("Device", "device.html"));
DefaultMutableTreeNode n2_node4_b2=
new DefaultMutableTreeNode(new ModuleInfo("Network", "network.html"));
DefaultMutableTreeNode n3_node4_b2=
new DefaultMutableTreeNode(new ModuleInfo("Users", "users.html"));
node4_b2.add(n1_node4_b2);
node4_b2.add(n2_node4_b2);
node4_b2.add(n3_node4_b2);
DefaultMutableTreeNode node5_b2=
new DefaultMutableTreeNode(new ModuleInfo("Logging", "logging.html"));
branch2.add(node1_b2);
branch2.add(node2_b2);
branch2.add(node3_b2);
branch2.add(node4_b2);
branch2.add(node5_b2);
* BRANCH 3 *
//adding to the Third branch
DefaultMutableTreeNode node1_b3=new DefaultMutableTreeNode("Status");
DefaultMutableTreeNode n1_node1_b3=new DefaultMutableTreeNode("Device");
DefaultMutableTreeNode n2_node1_b3=new DefaultMutableTreeNode("Network");
DefaultMutableTreeNode n3_node1_b3=new DefaultMutableTreeNode("Chassis");
DefaultMutableTreeNode n4_node1_b3=new DefaultMutableTreeNode("Resources");
node1_b3.add(n1_node1_b3);
node1_b3.add(n2_node1_b3);
node1_b3.add(n3_node1_b3);
node1_b3.add(n4_node1_b3);
DefaultMutableTreeNode node2_b3=new DefaultMutableTreeNode("Project Editor");
DefaultMutableTreeNode node3_b3=new DefaultMutableTreeNode("Project Manager");
DefaultMutableTreeNode node4_b3=new DefaultMutableTreeNode("Administration");
DefaultMutableTreeNode n1_node4_b3=new DefaultMutableTreeNode("Device");
DefaultMutableTreeNode n2_node4_b3=new DefaultMutableTreeNode("Network");
DefaultMutableTreeNode n3_node4_b3=new DefaultMutableTreeNode("Users");
node4_b3.add(n1_node4_b3);
node4_b3.add(n2_node4_b3);
node4_b3.add(n3_node4_b3);
DefaultMutableTreeNode node5_b3=new DefaultMutableTreeNode("Logging");
branch3.add(node1_b3);
branch3.add(node2_b3);
branch3.add(node3_b3);
branch3.add(node4_b3);
branch3.add(node5_b3);
tree=new JTree(top,true);
//tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
//Set the icon for leaf nodes.
ImageIcon deviceIcon = createImageIcon("/device.gif");
if (deviceIcon != null)
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(deviceIcon);
tree.setCellRenderer(renderer);
else
System.err.println("Leaf icon missing; using default.");
//Listen for when the selection changes.
tree.addTreeSelectionListener(this);
//Create the scroll pane and add the tree to it.
//JScrollPane treeView = new JScrollPane(tree);
tree.setToolTipText(" and ");
lPane.add(tree);
getContentPane().add(lPane);
// **************** end JTree ******************//
htmlPane = new JEditorPane();
htmlPane.setEditable(false);
initHelp();
JScrollPane rPane = new JScrollPane(htmlPane);
JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, lPane, rPane);
jsp.setDividerLocation(180);
getContentPane().add(jsp, BorderLayout.CENTER);
JPanel bPane = new JPanel();
JButton okButton = new JButton("Ok");
JButton applyButton = new JButton("Apply");
JButton clearButton = new JButton("Clear");
bPane.add(okButton);
bPane.add(applyButton);
bPane.add(clearButton);
getContentPane().add(bPane, BorderLayout.SOUTH);
setVisible(true);
/** Required by TreeSelectionListener interface. */
public void valueChanged(TreeSelectionEvent e)
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if (node == null) return;
Object nodeInfo = node.getUserObject();
if (node.isLeaf())
ModuleInfo module = (ModuleInfo)nodeInfo;
displayURL(module.moduleURL);
if (DEBUG)
System.out.print(module.moduleURL + ": \n ");
else
displayURL(helpURL);
if (DEBUG)
System.out.println(nodeInfo.toString());
private class ModuleInfo
public String deviceName;
public URL moduleURL;
public ModuleInfo(String device, String filename)
deviceName = device;
moduleURL = (URL)Example.class.getResource("/" + filename);
if (moduleURL == null)
System.err.println("Couldn't find file: "
+ filename);
public String toString()
return deviceName;
private void initHelp()
String s = "YFDemoHelp.html";
helpURL = Example.class.getResource("/" + s);
if (helpURL == null)
System.err.println("Couldn't open help file: " + s);
else if (DEBUG)
System.out.println("Help URL is " + helpURL);
displayURL(helpURL);
private void displayURL(URL url)
try
if (url != null)
htmlPane.setPage(url);
else
{ //null url
htmlPane.setText("File Not Found");
if (DEBUG)
System.out.println("Attempted to display a null URL.");
catch (IOException e)
System.err.println("Attempted to read a bad URL: " + url);
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path)
java.net.URL imgURL = Example.class.getResource(path);
if (imgURL != null)
return new ImageIcon(imgURL);
else
System.err.println("Couldn't find file: " + path);
return null;
public static void main(String args[])
new Example();
//new AssistiveExample();
}Thanks orozcomyes i can at the time of MIRO u can see both
go in SU01 for and user
in Parameters enter IVFIDISPLAY in Parameter ID and X in Paramater Value
thus for that user u will be able to c Invoice number and accounting number after saving MIRo
u will get message like
Invoice document 5105608893 was posted ( Accountng Documnt: 5100000000 )
hope this helps -
Xml in JTree: how to not collpase JTree node, when renaming XML Node.
Hi.
I'm writing some kind of XML editor. I want to view my XML document in JTree and make user able to edit contents of XML. I made my own TreeModel for JTree, which straight accesses XML DOM, produced by Xerces. Using DOM Events, I made good-looking JTree updates without collapsing JTree on inserting or removing XML nodes.
But there is a problem. I need to produce to user some method of renaming nodes. As I know, there is no way to rename node in w3c DOM. So I create new one with new name and copy all children and attributes to it. But in this way I got a new object of XML Node instead of renamed one. And I need to initiate rebuilding (treeStructureChanged event) of JTree structure. Renamed node collapses. If I use treeNodesChanged event (no rebuilding, just changes string view of JTree node), then when I try to operate with renamed node again, exception will be throwed.
Is there some way to rename nodes in my program without collpasing JTree?
I'am new to Java. Maybe there is a method in Xerces DOM implementation to rename nodes without recreating?
Thanks in advance.I assume that "rename" means to change the element name? Anyway your question seems to be "When I add a node to a JTree, how do I make sure it is expanded?" This is completely concerned with Swing, so it might have been better to post it in the Swing forum, but if it were me I would do this:
1. Copy the XML document into a JTree.
2. Allow the user to edit the document. Don't attempt to keep an XML document or DOM synchronized with the contents of the JTree.
3. On request of the user, copy the JTree back to a new XML document.
This way you can "rename" things to the user's heart's content without having the problem you described. -
hi,
i have a jtree with a specific renderer, this renderer returns a jlabel to represent each node in the tree. The text can be either bold or normal, based on custom properties of the node being rendered. Sometimes, during the execution of the program, these properties change and the jtree is refreshed, it all works fine and the nodes changed become bold as i want, the only problem is that if the text changes size, the full name does not appear. For example when i have a node with this name :
Inbox
When the property changes, and the nome becomes bold, the name changes to :
Inb...
I have tried everything i can but i just can't solve the problem. anyone knows?
best regards
ZedeIf you are using a DefaultTreeModel as your model, then when you change the text or the formatting of the node, call the model's nodeChanged(TreeNode) method.
-
Multiline text in a jtree node
i'm not able to add the multiline text in a jtree node. i've checked the data in both the cases before adding into the tree and after adding into the tree. itz getting the data in the proper format. but while displaying inside the tree itz taking into the single line.
kindly help me to get the data in a multi line format in the jtree.
thanks in advance.
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.text.*;
public class DynamicTreeDemo extends JPanel {
public static String transactionName=null;
String p1Name=null;
public static String duration=null;
public static final String NEWLINE = System.getProperty("line.separator");
static String[] arrCorrelatorId={"110","122","129","132","130","136","111","109","131","124","127",null};
static String[] arrParcorrelatorId={"108","110","122","129","122","130","108","108","109","121","121"};
static String[] arrtransactionName={"FINT3","FINT17","FINT20","FINT52","FINT21","FINT18","FINT4","FINT3"," FINT31","FINT19","FINT51"};
public static MutableTreeNode node;
public static DefaultTreeModel model;
public static TreePath path;
public static JTree tree;
static String[] nodeName={"FINT3_108","FINT17_110","FINT20_122","FINT52_129","FINT21_122","FINT18_110","FINT4_108","FINT3_108"," FINT31_109","FINT19_121","FINT51_121",null};
public DynamicTreeDemo(JFrame frame) {
final DynamicTree treePanel = new DynamicTree(transactionName);
populateTree(treePanel);
JTextField name = new JTextField(20);
setLayout(new BorderLayout());
treePanel.setPreferredSize(new Dimension(300, 150));
add(treePanel, BorderLayout.CENTER);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(10,50));
add(panel, BorderLayout.EAST);
public DefaultMutableTreeNode newObj(String parent){
DefaultMutableTreeNode pname= new DefaultMutableTreeNode(parent);
return pname;
public void populateTree(DynamicTree treePanel)
String p3;
DefaultMutableTreeNode p2,nNode, p1;
int ind=0, i=0,k=0, len=0, m=0;
boolean flag= false;
String desc;
while(nodeName[m]!=null)
p3 = nodeName[m];
ind = p3.indexOf("_");
p3 = p3.substring(0, ind);
desc=NEWLINE +"hi"+NEWLINE+"how r u";
if(arrParcorrelatorId[m].equals(arrParcorrelatorId[0]))
treePanel.addObject(null, p3,desc);
else{
int loopcount=0;
for(int j=0;nodeName[j]!=null;j++)
if(arrParcorrelatorId[m].equals(arrParcorrelatorId[j]))
for(int p=0;nodeName[p]!=null;p++)
if(arrCorrelatorId[p].equals(arrParcorrelatorId[j]))
p1=newObj(arrtransactionName[p]);
System.out.println("parent:"+p1);
System.out.println("child:"+p3);
treePanel.addObject(p1, p3,desc);
break;
break;
m++;
public static void showNodes(String corrId)
transactionName="FINT3";
public void DynamicDisplayNode(String corrId){
JFrame frame = new JFrame("DynamicTreeDemo");
showNodes(corrId);
Container contentPane = frame.getContentPane();
contentPane.setLayout(new GridLayout(1,1));
contentPane.add(new DynamicTreeDemo(frame));
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
frame.pack();
frame.setVisible(true);
public static void main(String[] args)
JFrame frame1=null;
DynamicTreeDemo demo= new DynamicTreeDemo(frame1);
demo.DynamicDisplayNode("108");
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.Enumeration;
import java.util.StringTokenizer;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.*;
public class DynamicTree extends JPanel {
protected DefaultMutableTreeNode rootNode;
protected DefaultTreeModel treeModel;
protected JTree tree;
protected DefaultTreeCellRenderer linksRenderer;
public static final String NEWLINE = System.getProperty("line.separator");
public DynamicTree(String appName) {
rootNode = new DefaultMutableTreeNode(appName);
treeModel = new DefaultTreeModel(rootNode);
tree = new JTree(treeModel);
tree.setEditable(false);
tree.setShowsRootHandles(true);
tree.setBackground(Color.white);
tree.setCellRenderer(new DefaultTreeCellRenderer()
public Component getTreeCellRendererComponent(JTree pTree,
Object pValue, boolean pIsSelected, boolean pIsExpanded,
boolean pIsLeaf, int pRow, boolean pHasFocus)
DefaultMutableTreeNode node = (DefaultMutableTreeNode)pValue;
JLabel lbl = (JLabel)super.getTreeCellRendererComponent(pTree, pValue, pIsSelected,pIsExpanded, pIsLeaf, pRow, pHasFocus);
lbl.setBorder(new LineBorder(Color.RED,1));
/* Component c = super.getTreeCellRendererComponent(pTree, pValue, pIsSelected,
pIsExpanded, pIsLeaf, pRow, pHasFocus);
if (node.isRoot())
c.setForeground(Color.red);
else if (node.getChildCount() > 0)
c.setForeground(Color.blue);
else if (pIsLeaf)
c.setForeground(Color.black);//new Color(0x736AFF));*/
setBackgroundNonSelectionColor(Color.white);
JPanel p = new JPanel();
p.setBackground(tree.getBackground());
Dimension d = lbl.getPreferredSize();
p.setPreferredSize(new Dimension(d.width, d.height));
p.add(lbl);
tree.setRowHeight(30);
return (p);
JScrollPane scrollPane = new JScrollPane(tree);
setLayout(new GridLayout(1,0));
add(scrollPane);
public void addObject(DefaultMutableTreeNode parent,Object child,String desc)
child=child+desc;
//System.out.println("child"+child);
DefaultMutableTreeNode parent1;
DefaultMutableTreeNode childNode =
new DefaultMutableTreeNode(child);
if (parent == null)
parent = rootNode;
else
String parentName = (String)parent.getUserObject();
String tok;
Enumeration e=null;
e=(Enumeration) rootNode.breadthFirstEnumeration();
int breakloop=0;
parent = rootNode.getLastLeaf();
while (e.hasMoreElements() ) {
if(parent!= null)
//System.out.println("parent.toString():"+parent.toString());
tok=parent.toString();
StringTokenizer st = new StringTokenizer(tok);
parent1=newObj(st.nextToken());
if(parent1.getUserObject().equals(parentName))
breakloop=1;
break;
parent= parent.getPreviousNode();
if(breakloop==0)
parent = rootNode.getLastLeaf();
System.out.println("parent.toString():"+parent.toString());
System.out.println("childNode"+childNode.toString());
parent.add(childNode);
public DefaultMutableTreeNode newObj(String parent){
DefaultMutableTreeNode pname= new DefaultMutableTreeNode(parent);
return pname;
class MyTreeModelListener implements TreeModelListener {
public void treeNodesChanged(TreeModelEvent e) {
DefaultMutableTreeNode node;
node = (DefaultMutableTreeNode)
(e.getTreePath().getLastPathComponent());
try {
int index = e.getChildIndices()[0];
node = (DefaultMutableTreeNode)
(node.getChildAt(index));
} catch (NullPointerException exc) {}
public void treeNodesInserted(TreeModelEvent e) {
public void treeNodesRemoved(TreeModelEvent e) {
public void treeStructureChanged(TreeModelEvent e) {
}Here is a simple example.
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class MultiLineTreeDemo extends JFrame {
private JTree tree;
public static void main( String[] args ) throws Exception {
SwingUtilities.invokeLater( new Runnable() {
public void run() { new MultiLineTreeDemo(); }
public MultiLineTreeDemo() {
super( "MultiLineTreeDemo" );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
DefaultMutableTreeNode root = new DefaultMutableTreeNode( "<html>This is<p>the root node.</html>" );
DefaultMutableTreeNode node = new DefaultMutableTreeNode( "<html>This is<p>a child node.<html>" );
root.add( node );
tree = new JTree( root );
setLayout( new BorderLayout() );
JScrollPane scrollPane = new JScrollPane( tree );
add( scrollPane, BorderLayout.CENTER );
setSize( 200, 200 );
setVisible( true );
} -
WLST - Failing to run nmConnect() command / node manager becomes unreachabl
Hello guys,
I'm facing some issues to setup some configurations of one application that I've deployed on weblogic 10.3.3.0.
One of the needed steps in order to configure this applications is open the WLST in offline mode an run 2 commands:
*/bea/mytrack/wlserver_10.3/common/bin/wlst.sh*
Then I try to connect in the nodemanager:
* wls:/offline> nmConnect('admin30800','weblogic_password',port='30801',domainName='track30800')*
The following error returns:
Connecting to Node Manager ...
<Jul 13, 2011 2:23:45 PM CDT> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=thawte Primary Root CA - G3,OU=(c) 2008 thawte\, Inc. - For authorized use only,OU=Certification Services Division,O=thawte\, Inc.,C=US". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
<Jul 13, 2011 2:23:45 PM CDT> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=T-TeleSec GlobalRoot Class 3,OU=T-Systems Trust Center,O=T-Systems Enterprise Services GmbH,C=DE". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
<Jul 13, 2011 2:23:45 PM CDT> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=T-TeleSec GlobalRoot Class 2,OU=T-Systems Trust Center,O=T-Systems Enterprise Services GmbH,C=DE". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
<Jul 13, 2011 2:23:45 PM CDT> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=GlobalSign,O=GlobalSign,OU=GlobalSign Root CA - R3". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
<Jul 13, 2011 2:23:45 PM CDT> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "OU=Security Communication RootCA2,O=SECOM Trust Systems CO.\,LTD.,C=JP". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
<Jul 13, 2011 2:23:45 PM CDT> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=VeriSign Universal Root Certification Authority,OU=(c) 2008 VeriSign\, Inc. - For authorized use only,OU=VeriSign Trust Network,O=VeriSign\, Inc.,C=US". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
<Jul 13, 2011 2:23:45 PM CDT> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=KEYNECTIS ROOT CA,OU=ROOT,O=KEYNECTIS,C=FR". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
<Jul 13, 2011 2:23:45 PM CDT> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=GeoTrust Primary Certification Authority - G3,OU=(c) 2008 GeoTrust Inc. - For authorized use only,O=GeoTrust Inc.,C=US". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
Traceback (innermost last):
File "<console>", line 1, in ?
File "<iostream>", line 123, in nmConnect
File "<iostream>", line 646, in raiseWLSTException
WLSTException: Error occured while performing nmConnect : Cannot connect to Node Manager. : Access to domain 'track30800' for user 'admin30800' denied
I did some research and found this thread here: http://kr.forums.oracle.com/forums/thread.jspa?threadID=788163
that solves the initial problem, however after I performed the nmConnect and a storeUserConfig() command, I exit() from the WLST and restart the node manager with success, the node manager becomes unreachable.
I used the WL adm console and access -> appdomain -> environments -> machines -> monitoring -> node manager status to check the unreachable status.
Thanks in advance,
DavinodNice it worked!!
However when I try to start the servers controlled by this node manager I got this error:
-sh-3.2$ <Jul 14, 2011 8:43:42 AM> <WARNING> <Exception while starting server 'track30800-01'>
java.io.FileNotFoundException: /u01/track30800/user_projects/domains/track30800/servers/track30800-01/data/nodemanager/boot.properties (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at weblogic.nodemanager.server.ServerManager.saveBootIdentity(ServerManager.java:495)
at weblogic.nodemanager.server.ServerManager.saveStartupConfig(ServerManager.java:438)
at weblogic.nodemanager.server.ServerManager.start(ServerManager.java:301)
at weblogic.nodemanager.server.Handler.handleStart(Handler.java:567)
at weblogic.nodemanager.server.Handler.handleCommand(Handler.java:118)
at weblogic.nodemanager.server.Handler.run(Handler.java:70)
at java.lang.Thread.run(Thread.java:619)
Jul 14, 2011 8:43:42 AM weblogic.nodemanager.server.Handler handleStart
WARNING: Exception while starting server 'track30800-01'
java.io.FileNotFoundException: /u01/track30800/user_projects/domains/track30800/servers/track30800-01/data/nodemanager/boot.properties (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at weblogic.nodemanager.server.ServerManager.saveBootIdentity(ServerManager.java:495)
at weblogic.nodemanager.server.ServerManager.saveStartupConfig(ServerManager.java:438)
at weblogic.nodemanager.server.ServerManager.start(ServerManager.java:301)
at weblogic.nodemanager.server.Handler.handleStart(Handler.java:567)
at weblogic.nodemanager.server.Handler.handleCommand(Handler.java:118)
at weblogic.nodemanager.server.Handler.run(Handler.java:70)
at java.lang.Thread.run(Thread.java:619)
<Jul 14, 2011 8:43:42 AM CDT> <Error> <NodeManager> <BEA-300048> <Unable to start the server track30800-01 : Exception while starting server 'track30800-01'>
Edited: Should I change the chmod for 777 for this file in order to check that all users have write permission?
-rw-r--r-- 1 root iluser 193 Jun 24 11:05 boot.properties
Did I miss a step?
Thanks,
Davinod
Edited by: davinod on Jul 14, 2011 6:58 AM -
Set different color for one JTree node
hello,
I managed to find how to set a color for Jtree nodes but the problem is that with my method all the nodes will b the same color whereas i'm looking to have nodes of different color depending on the situation.
the method for setting all Jtree nodes the same color(other than black):
tree.setCellRenderer(
new DefaultTreeCellRenderer() {
public Color getTextNonSelectionColor() {
return Color.lightGray; } });I WANT TO CHOSSE EACH COLOR FOR EACH NODE
help plz
thanksYou need to implement TreeCellRenderer interface
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus)You can know which node is rendering by check value argument. Please read DefaultTreeCellRenderer's code. -
Customizing JTree Nodes ImageIcons???
I have a JTree. Iam trying to customize the icons of it instead of the defaulticons available for leaf and branch nodes.I successfully set a new icon for leaf nodes by calling setLeafIcon.Also i can use setOpenIcon and setClosedIcon for the expanded and closed branches.
But in my application when my GUI is launched i actually set the JTree in its fully expansion form.
so there is no difference between setOpenICon and setClosedIcon as all of them are expanded.so how do i differentiate between the two and set different icons for both of them.
exmaple:Cricket club is my root node..I have for ex:ABC , BCD, and CDE club underneath that(branch nodes).Under each club i have player1,player2, player3. .etc..so i want to set 3 different icons,,one for cricket club, 2nd for ABC,BCD andCDE clubs and 3rd one for players.since my JTree is expanded the same icon is set for CricketClub(root Node) and ABC,BCD and CDE club(branch nodes)..How can iset different icons to these. can anyone help me on this..I am sort of new to JTree.So code snippet will be a welcome..
Thanks Much in advanceTo fully expand the tree, use the method scrollPathToVisible(TreePath path). The path is the path for your tree's last node. The DefaultMutableTreeNode class should have some methods to find the path for a particular node.
To set the icons for a particular node, depending on their opened or closed state, Make a subclass of TreeCellRenderer. If you look at the API for TreeCellRenderer, you will see that it will tell you if the current node is expanded, selected, leaf, hasfocus, etc...
If you want to set an open icon for an expanded node, just check if it is expanded. Cast the Object value to a DefaultMutableTreeNode and set the Icon for it, unless you have your own class for your nodes. Lastly, set your renderer for your JTree with setCellRenderer(TreeCellRenderer ren). I hope this helps. -
Can not highlight a JTree node programmatically
Hi Swing lovers,
I can select a node using setSelectionPath. Unfortunately I can not find a way to show the user that the node is selected. I know it can be done. When traversing the tree with the up- and down keyboard arrow, it shows what I want to see.
Am I overlooking some method here?
Thanks a lot for the tip,
ErikThanks DrClap,
I expected to find an easy way to mark a jTree node as being selected. However the TreeCellRenderer does the job. See the code snipped below:
public JTree jTree1 = new JTree();
private TreeNode currentNode = null;
//assing currentNode somewhere in you code
jTree1.setCellRenderer(new MyRenderer());
private class MyRenderer extends DefaultTreeCellRenderer {
public MyRenderer() {
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
if (currentNode != null) {
if (value.hashCode() == currentNode.hashCode()) sel = true;
super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
return this;
/ -
Setting bold font for nodes which are not leaf nodes
In JTree, is it possible to set the font for nodes which are not leaf nodes. Can I do this without using custom renderer, or at the most using a DefaultTreeCellRenderer ?
regards,
nirvanIn JTree, is it possible to set the font for nodes which are not leaf nodes. Can I do this without using custom renderer, or at the most using a DefaultTreeCellRenderer ?
regards,
nirvan -
How to post an Event (mouse left click) to JTree node
Hi,
I am using JTree for my application just like the windows explorer tree. By default, Jtree node will got focus using left click. But, I'd like that my tree will detect a right click so that I can copy any file to the Jtree. I've added a mouselistener to it but the node is not selected by the right click. Anyboby can teach me how to post a mouse left click event to the Jtree so that it will become selected using left click.
Thanks a millionSee if this is useful
public void mouseClicked(MouseEvent event)
Object object = event.getSource();
if (object == mTree)
mTree_mouseClicked(event);
private void mTree_mouseClicked(MouseEvent event)
if(event.getModifiers()==event.BUTTON3_MASK)
//your logic goes here
}//close method -
Hi,
I am interested in whats the easiest way to sort jTree Nodes alphabetically. Is there any Method to do this directly or may i use something like quicksort?
Thanks for help
MircoThanks Hamed,
Well, I work in your code, and I post here.
public static DefaultMutableTreeNode sortTree(DefaultMutableTreeNode root) {
for (int i =0; i<root.getChildCount()-1; i++) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i);
String nt = node.getUserObject().toString();
for (int j=i+1;j<=root.getChildCount()-1;j++)
DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) root.getChildAt(j);
String np = prevNode.getUserObject().toString();
System.out.println(nt+" "+np);
if (nt.compareToIgnoreCase(np)>0) {
root.insert(node, j);
root.insert(prevNode, i);
if (node.getChildCount() > 0) {
node = sortTree(node);
return root;
}and this code I used after include in jtree
public void jTreeSortingBegin()
dn = (DefaultMutableTreeNode)treeModel.getRoot();
treeModel.reload();
dn = sortTree(dn);
treeModel.reload(dn);
}for exemple
addObject(jTextField1.getText());
jTreeSortingBegin();
Maybe you are looking for
-
I am trying to syne my new Iphone4S with outlook on my pc. I am following the instructions using Itunes. However I am getting a message that the pairing software is not there. what is this and how do I get it?
-
How do I get my Gear Pro camera work on my IMac?
How do I get my Gear Pro camera work on my IMac? Just bought one of those action cameras - Gear Pro However doesn't seem to work yet on my IMac, any suggestions on how to get this going Imac is from 2010 thanks
-
One Workcenter for multiple machines and multiple labor.
ZHi, I have to map a scenario in which i have 10 machines, that do same operation, have same cycle time for product, same capacity. So i have clubbed these together and maintained "No. of Individual Capacities" in workcenter as 10 and created 1 workc
-
DATA: t184 LIKE TABLE OF t184 WITH HEADER LINE. DATA: BEGIN OF pstyd OCCURS 0, pstyd TYPE pstyd, END OF pstyd. LOOP AT t184. pstyd-pstyd = t184-psty1. APPEND pstyd. pstyd-pstyd = t184-psty2. APPEND pstyd. pstyd-pstyd = t184-psty3. APPEND psty
-
X Through battery icon, no LED light on MagSafe, 2 month old Macbook Pro
This all started this afternoon. I noticed a black X through the battery icon in the upper tool bar, then noticed that there was no LED light on the MagSafe charger. The fan on my computer was also constantly running. This computer is only TWO months