How to set Jtree Nodes' name into TextField??

Dear Sir:
I have following code to select any file's name then put into TextField,
see:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
public class JTreeSplitChooseDemo extends JPanel implements ActionListener{
    JFileChooser fc;
    JButton openButton, saveButton;
    JTextField jtf;
  public JTreeSplitChooseDemo() {
    final JTree tree;
    final JTextField jtf;
    JPanel jp= new JPanel();
    setPreferredSize(new Dimension(500,350));
    jp.setPreferredSize(new Dimension(500,300));
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");
    DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
    top.add(a);
    DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
    a.add(a1);
    DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
    a.add(a2);
    DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
    top.add(b);
    DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
    b.add(b1);
    DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
    b.add(b2);
    DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
    b.add(b3);
    tree = new JTree(top);
    JScrollPane jsp = new JScrollPane(tree);
    jsp.setPreferredSize(new Dimension(500,300));
    tree.setPreferredSize(new Dimension(500,300));
    add(jsp, BorderLayout.CENTER);
    jtf = new JTextField("", 20);
    add(jtf, BorderLayout.SOUTH);
    tree.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent me) {
        TreePath tp = tree.getPathForLocation(me.getX(), me.getY());
        if (tp != null)
          jtf.setText(tp.toString());
        else
          jtf.setText("");
  public JPanel JTreeText() {
         JPanel jp= new JPanel();
         JPanel jpanel= new JPanel();
         setPreferredSize(new Dimension(400,350));
         jp.setPreferredSize(new Dimension(400,300));
         JScrollPane jsp = new JScrollPane(jp);
         jsp.setPreferredSize(new Dimension(400,300));
         jpanel.add(jsp, BorderLayout.CENTER);
         jtf = new JTextField("", 20);
         fc = new JFileChooser();
         openButton = new JButton("Open a File...",new ImageIcon("images/hui.gif"));
         openButton.addActionListener(this);
         JPanel buttonPanel = new JPanel(); //use FlowLayout
         buttonPanel.add(openButton);
         //jp.add(buttonPanel, BorderLayout.PAGE_START);
         jp.add(buttonPanel, BorderLayout.NORTH);
         jp.add(jtf, BorderLayout.CENTER);
         return jpanel;
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new JTreeSplitChooseDemo(), new BorderLayout().WEST);
    frame.getContentPane().add(new JTreeSplitChooseDemo().JTreeText(), new BorderLayout().CENTER);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800, 350);
    frame.setVisible(true);
@Override
public void actionPerformed(ActionEvent e) {
     //Handle open button action.
    if (e.getSource() == openButton) {
      int returnVal = fc.showOpenDialog(JTreeSplitChooseDemo.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
         jtf.setText(file.getName());
      } else {
         jtf.add("Open command cancelled by user.", null);
}For example, If i choose file : C:\temp\ftp\TestMyFile.txt
after I press open button, then choose it, then, the file name TestMyFile.txt will be displayed in the textFiled.
My problem is that I hope to choose any node in the JTree on the left Panel, then when I choose it, this JNode I selected will be displayed its name in the TextField.
Not file, I need choose JNode,
ie, B1 under B node, or A1 under A node, then B1 will be displayed in jtf.
How to do this one??
Can Guru throw some light??
Thanks
sunny

Thanks, camickr.
My fault not to explain detail.
Actually I mean that I will use a dialog box(very much look like a file choose) that is something like a file chooser then I can browse over JTree first for any node then I can choose or select a node in this JTree, after select this node, its name is populated into text field. My one is I will use a JTree browser (something like that) to get a tree node.
ie, this showOpenDialog will browse over JTree, not File system.
I did not want to click on the node then this node name is populated into textField.
the sample (http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html) shows that when I select a node, then its name was populated to a destination.

Similar Messages

  • How to change JTree nodes background?

    hello there
    i have a jtree which i set its background to red
    but the nodes background is still white
    why?and how to set the nodes background to red too?
    and how to remove the tree border
    because i tried setting it to null and it doesn't work?
    here is my code:
    package view;
    import java.awt.Color;
    import javax.swing.*;
    import javax.swing.tree.*;
    class TreeComponent{
      public static void main(String[] args) {
        JFrame frame = new JFrame("Creating a JTree Component!");
        DefaultMutableTreeNode parent = new DefaultMutableTreeNode("Color", true);
        DefaultMutableTreeNode black = new DefaultMutableTreeNode("Black");
        DefaultMutableTreeNode blue = new DefaultMutableTreeNode("Blue");
        DefaultMutableTreeNode nBlue = new DefaultMutableTreeNode("Navy Blue");
        DefaultMutableTreeNode dBlue = new DefaultMutableTreeNode("Dark Blue");
        DefaultMutableTreeNode green = new DefaultMutableTreeNode("Green");
        DefaultMutableTreeNode white = new DefaultMutableTreeNode("White");
        parent.add(black);
        parent.add(blue);
        blue.add(nBlue);
        blue.add(dBlue);
        parent.add(green );
        parent.add(white);
        JTree tree = new JTree(parent);
        tree.setBackground(Color.red);
        tree.setBorder(null);
        frame.add(tree);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setUndecorated(true);
        frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        frame.setSize(200,200);
        frame.setVisible(true);
    }

    how to set the nodes background to red too?
    ((JComponent) tree.getCellRenderer()).setOpaque(true);[/code\
    how to remove the tree borderWhat border?
    db                                                                                                                                                                                                                                                                                                                                       

  • Could someone help me out how to insert a Node properly into a DOM?

    I am trying to insert a Node built from a String to a DOM.
    Here is how I created the Node
                   Detail = "<Detail><Msg>Detail Message</Msg></Detail>";
                   prolog = "<?xml version="1.0" encoding="UTF-8"?>";
                   Node DetailNode = null;
                   Document DetailDoc = null;
                   if( Detail != null ){
                        Detail = prolog + BiometricDetail;
                        DetailDoc = xp.XML2DOM( BiometricDetail ); // transform a XML String into a DOM.
                        DetailNode = BiometricDetailDoc.getDocumentElement();                    
    Here is how I created the DOM
                   javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
                   javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
                   Document document = builder.newDocument();
                   Element beeE = document.createElement("BeeSets");
                   Element grpE = document.createElement("Group");          
                   bioE.appendChild( grpE );
                   // the document looks like "<BeeSets><Group></Group><BeeSets>";
                   // After inserting the Node DetailNode, I want it to look like
                   // "<BeeSets><Group><Detail><Msg>Detail Message</Msg></Detail></Group><BeeSets>";
    Now when I tried to insert the node DetailNode to the DOM document, I tried
    1) document.importNode( DetailNode, true );               
    No exception was thrown. But when I transformed the DOM document back to a String, I could not see the information from the newly imported Node DetailNode.
    When I tried
              grpE.insertBefore( BiometricDetailNode, dataE );
    I got the following exception.
         org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
         at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknown Source)
         at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
         at com.jadcs.bioidentity.role.base.RP.getNodes(RP.java:497)
    2) document.adoptNode( DetailNode );
    I got the following exception.
         java.lang.ClassCastException: org.apache.xerces.dom.DocumentImpl
         at org.apache.xerces.dom.DeferredTextImpl.synchronizeData(Unknown Source)
         at org.apache.xerces.dom.NodeImpl.setOwnerDocument(Unknown Source)
         at org.apache.xerces.dom.ParentNode.setOwnerDocument(Unknown Source)
         at org.apache.xerces.dom.ElementImpl.setOwnerDocument(Unknown Source)
         at org.apache.xerces.dom.ParentNode.setOwnerDocument(Unknown Source)
         at org.apache.xerces.dom.ElementImpl.setOwnerDocument(Unknown Source)
         at org.apache.xerces.dom.CoreDocumentImpl.adoptNode(Unknown Source)
         at com.jadcs.bioidentity.role.base.RP.getNodes(RP.java:509)
    3) detailStr = "<Detail><Msg>Detail Message</Msg></Detail>";
    Element detailE = document.createElement("Detail");
    detailE.setTextContent( detailStr );
    grpE.appendChild( detailE );
    This way gives result like "<BeeSets><Group><Detail><Detail><Flash>On</Flash></Detail></Detail></Group><BeeSets>";
    The content is messed up.
    Could someone help me out at how to insert a Node properly into a DOM? Thank you very much.

    Said another way, importNode actually only makes and returns a copy of the node you gave it (it will be a deep copy only if you pased true as the second parameter), but where the new dom you called import on is owner.
    So what you need to do is more like this:
    Node tempNode = domYouAreAddingTheNodeTo.importNode(node2copy,true); //true if you want a deep copy
    domYouAreAddingTheNodeTo.appendNode(tempNode);You can also traverse to any point in the DOM and insert the node there with the same method, but you always have to import first so that the DOM has a copy of the node that it owns.

  • How to set attched file name while sending email through ABAP

    Hi All- tell me how to set attched file name while sending email through ABAP.
    regards...
    Abhay

    Sure,  when you are adding your entry to the packing list,  give the name in the obj_name field.
    *File 2
      mailbin = 'This is file 2'.
      append mailbin.
      data: start type i.
      data: end type i.
      start = tab_lines + 1.
      describe table mailbin lines end.
      mailpack-transf_bin = 'X'.
      mailpack-head_start = 1.
      mailpack-head_num = 1.
      mailpack-body_start = start.
      mailpack-body_num = end.
      mailpack-doc_type = 'TXT'.
      mailpack-obj_name = 'TEST2'.        "<-  RIGHT HERE
      mailpack-obj_descr = 'Subject'.
      mailpack-doc_size = tab_lines * 255.
      append mailpack.
    Regards,
    RIch Heilman

  • How to get the tag name into javascript

    Hi,
    Is there any way to get the tag name into java script when user clicks on.
    For eg: if i use netui:anchor tag, how can I pass the tag id to the javascript when user clicks on the link using onClick attribute. This tag id needs to be evaluated at run time.
    Ex code is given below.
    function fun1(){
    // how to get the tag name;
    <%
    String st="hai";
    %>
    <netui:anchor action="x" onClick="fun1()" tagId="<%=st%>>
    I want to get this tagId (st) to the java script function fun1() when user clicks on this link. How can I do that. can you please help in this issue.
    Thanks,
    Satish.

    Hi,
    You can set the java variable as a js variable at run time:
    <script>
    var anchorName = <%=getNetuiTagName%>;
    function fun1()
    var anchorID = getNetuiTagName(anchorName);
    alert(anchorID);// this will show the rendered ID for the anchor specified
    </script>
    this works because the jsp variable will be rendered before the js.
    Thanks,
    Steve

  • How to get the node name?

    Hi Guys,
    I have a path that look like this root/1stLevel/dynamicLevel
    how can i get the dynamic level node name when it come with different node name so that i can catch it into one of the variable?
    it may change according to the requester
    root/1stLevel/dynamicLevel1
    root/1stLevel/dynamicLevel2
    root/1stLevel/dynamicLevel3
    root/1stLevel/dynamicLevel4

    What software? In OSB try Assign with this expression:
    fn:name($body/root/firstLevel/*[1])By the way, you can't use element named "1stLevel" because it starts with number.

  • How to sort Jtree node?

    Now, I want to sort tree node by increasing.
    for example there are three child node:
    [20 -40][
    10 - 20]
    [30- 60].
    they are added to JTree node by different order.but are shown in increasingorder.
    like this:
    [10 - 20]
    [20 -40][
    [30- 60].
    how to control tree node.

    Implement the Comparable interface in t he userobject class and possibly the toString(0 as well.
    Ex.
    public class UserObject implements java.lang.Comparable{
    public int compareTo(Object obj) throws ClassCastException
    public String toString()

  • How to set a database name for fetching metadata?

    How can I tell an already-existing Connection what its database should be, in such a way that I can successfully get MetaData from the connection?
    If I use the following code, everything works fine:
         Connection connection;
         DatabaseMetaData metadata;
         ResultSet rs;
         connection = DriverManager.getConnection("jdbc:mysql://Localhost/archival", mUser, mPassword); // replace this line
         metadata = connection.getMetaData();
         rs = metadata.getTables(null, null, "%", null);
    But if I replace the fourth line above with these three lines:
         connection = DriverManager.getConnection("jdbc:mysql://Localhost/", mUser, mPassword);
         Statement stmt = connection.createStatement();
         stmt.execute("USE archival");
    then I get a SQLException "Incorrect database name: ''". I would really prefer to factor my getConnection() code so that it doesn't have to know what the database-name is, but in order to do that I need to be able to set the database-name after the connection has been created, and still get MetaData on the connection.
    TIA for any help!

    Umm I probably totally don't understand the question, but you can change the name in the IDE,
    and in code you can name it to whatever you want
    Dim WhatEverNameIWantToGive as new button Dim secondbutton = WhatEverNameIWantToGive
    or maybe you mean
    public class mybutton
    inherits button
    'your custom code here
    end class

  • How to Set the JNDI name in J2EE 1.4 ??

    Hello,
    I am sure i am have done everything right except for the JNDI name ! I have recently shifted to J2EE 1.4. I was using j2EE 1.2.
    So kindly tell me how should i set me JNDI name in the deploytool.
    Here is the exception i got when i tried to run my application without having set any JNDI name !!
    http://img220.imageshack.us/img220/832/hellodt5.gif
    Thanks.

    There are 2 types of descriptors:
    standard and portable deployment descriptors (e.g. ejb-jar.xml, web.xml, application.xml, etc)
    vendor specific deployment plan (e.g., sun-ejb-jar.xml, sun-web.xml, sun-application.xml, jboss.xml, weblogic.xml, etc)
    When you are developing ejb apps with glassfish, or JavaEE SDK, or Sun Java System Application Server, you usually package all descriptors in META-INF directory inside the jar.
    You can also create portable apps that do not contain any vendor specific deployment plans. So you can deploy it to any appserver. At deployment time, you then specify an option to pass the deployment plan to deploy tool. This is required by JSR 88 and all J2EE- or JavaEE-compliant appserver must support this.
    In Glassfish, JavaEE SDK, or SJSAS, you can:
    $SJSAS_HOME/bin/asadmin deploy --deploymentplan /tmp/deploy-plan.jar /tmp/my-ejb.jar
    where /tmp/deploy-plan.jar is a jar file containing sun-ejb-jar.xml for the deployable ejb-jar:
    jar tvf deployment-plan.jar
    0 Thu Oct 12 11:55:00 EDT 2006 META-INF/
    106 Thu Oct 12 11:54:58 EDT 2006 META-INF/MANIFEST.MF
    570 Thu Oct 12 11:55:00 EDT 2006 sun-ejb-jar.xml

  • How to set the card name of wml in Simple Result?

    Hi,
    I nned to set the card name appearing in the WML device (browser show the name of the card in the top of the screen)
    How do i set an page tile in SR? I cant find such a parameter any where on the tags... Ideas?
    Regards,
    Lars

    Lars,
    You may use SimpleTitle element to display the title. See the following example copied herewith from developer's guide.
    <?xml version = "1.0" encoding = "UTF-8" standalone="yes" ?>
    <!DOCTYPE SimpleResult PUBLIC "-//ORACLE//DTD SimpleResult 1.1//EN" "http://xmlns.oracle.com/ias/dtds/SimpleResult_1_1_0.dtd">
    <SimpleResult bgcolor="99ff99">
    <SimpleContainer>
    <SimpleText>
    <SimpleTitle>Seach Result</SimpleTitle>
    <SimpleTextItem>
    <SimpleEm level="strong">1 Entry found</SimpleEm>
    <SimpleBreak msecs="500"/>
    <SimpleStrong level="strong">Chandra Patni</SimpleStrong>
    <SimpleBreak/>400 Oracle Pkwy
    <SimpleBreak/>Redwood Shores
    <SimpleBreak/>CA, 94065
    </SimpleTextItem>
    </SimpleText>
    </SimpleContainer>
    </SimpleResult>

  • HOw to get parent node name value through its child node?

    Hi,
    Experts,
    I am able to get child node name values but according to attribute name value i want to  get its parent name value how to achieve that. For that i have used If_Ixml_element->Get_parent. Please pass some idea on it.
    Thanks in advance,
    Shabeer ahmed.

    Hello Shabeer
    I think the coding should be straightforward:
    DATA: lo_element   TYPE REF TO if_ixml_element,
              lo_child        TYPE REF TO if_ixml_node,
              lo_parent      TYPE REF TO if_ixml_node.
    " NOTE: LO_ELEMENT holds your child node
      lo_child ?= lo_element.
      lo_parent = lo_child->get_parent( ).
    Regards
      Uwe

  • [SOLVED] How to set the packager name for an AUR package?

    Hi,
       I'm maintaining an AUR package (fspcc), but I don't know how to set the name of the "packager" for that package.
    E.g. when you request info about some package
        $ pacman -Qi somepkg
    there is a line
        Packager: Unknown Packager
    that specifies the packager.
    How do I set this "Packager" info so that any user installing my package will see what I want?
    Last edited by lisztinf (2014-04-13 13:39:43)

    Thanks for the answer.
    I guess that when I run
       $ makepkg
    in my local build directory, then "mkpkg" will build a package with the "Packager" info set accordingly to my local makepkg.conf.
    However, I would like another user - with his own makepkg.conf - to see what I want when installing the package. How can I achieve this?
    If I install an official package - say pacman itself - through ABS, I see the "Packager" field properly set for that official package. But certainly this info doesn't come from my local makepkg.conf. I would like the same behaviour for my package. Is it possible?

  • How to set dynamic table name in sql query?

    I want set dynamic table name by parameter in sql query,just like:
    select * from :tbname
    but run report is error,BI P report table name is invalidation.
    What can i do? Thanks!

    Hi,
    that's only possible inside a data template with a lexical parameter.
    Regards
    Rainer

  • How to set dynamic host name in the URL of a URL iView?

    Hello,
    I am using a standard URL iView that points to some J2EE app I've written and deployed on the same server.
    I would like to set the host name to be a dynamic one, this way I won't need to change the iView URL when transporting it from one portal to another. As far as I know the system for a URL iView only controls authorizations but cannot replace the full URL set in the iView.
    Any idea who can this be achieved?
    Roy

    Hi Mrityunjay,
    forced URL at runtime will require me to call the URL iView from another iView that I will need to code (setting the URL in the Request object). If I did all this I might as well call it from this iView already.
    I would like to do it with no further developments. I would have thought that SAP has constants that can be plugged in the URL for this type of thing, i.e. $hostname...
    Rgds,
    Roy
    Edited by: Roy Cohen on Aug 21, 2008 4:03 PM

  • How to set proxy server name in iasenv.ksh?

    How to set the proxy server host and port in the JAVA_ARGS list in the iasenv.ksh file? IAS 6.5 is the server being used.

    hi,
    Below is what needs to be done.
    1. Edit the variable JAVA_ARGS in iasenv.ksh to include the -Dhttp.proxyHost. For example, the JAVA_ARGS looks like this : JAVA_ARGS="-Xss512k -Xms64m -Xmx64m -Dhttp.proxyHost=proxy.myhost.com -Dhttp.proxyPort=8080"
    2. This JAVA_ARGS is the one under the kjs script settings. You will find this below the comment ## Set all user level JVM flags for KJS here.
    3. Now stop and restart the application server.
    4. Any new URL connections from the servlets/applications within the appserver will now go through the proxy server.
    I have tested this on iAS6.0 SP3. But this should work in 6.5 too. Please let me know if this helps.
    Cheers,
    Vasanth

Maybe you are looking for

  • Windows 8.1 crashing/rebooting

    My windows 8.1 is rebooting multiple times per day. I've uploaded all the dmp files to my skydrive. Here's the output/report for WhoCrashed.  I'm not sure how to troubleshoot from here. computer name: P6X58D-FLL windows version: Windows 8 , 6.2, buil

  • Configure apple tv via external cable media box

    I've got an older tv with only 1 hdmi output which is being used now by my cable media box.  I also use a bose receiver for audio.  Can anybody give me any tips on how I need to configure this - ie, if I need to run everything via the bose receiver o

  • Uh-oh... Boot failure, out of the blue

    Got nothing but a loud fan sound when I turned on my G5's power this morning. No chime, nothing. I forced shutdown by holding the power button; then I disconnected the power cord for a minute. Next boot was completely normal, and it has been running

  • Error message on 4506R

    Hi, I have got 2 numbers of 4506 which are connected to the 6500 switch the connectivity to the core switch is over the two different port channel (2 physical interface for each port channel. No I am getting the below error message please let me know

  • Document for deployment descriptor and config

    Hi, I just downloaded wls8.1. I am browsing the online document. I ca't find any document on config.xml (there is one in 70). I can't find the deployment descriptor too like application.xml, weblogic-application.xml Thanks