How can I put JTree into drop-down List of JCombobox

I want to create a drop-down list which shows a list of nodes. When the user clicks on a node, it should open to show the leafs. Clicking on a leaf should close the ComboboxPopup and show its value. Creating a renderer only represent my tree, but I can't trap the events.
Here is my simplified code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.border.*;
import java.util.*;
public class ComboBoxTreeDemo  extends JPanel
     static JFrame frame;
     ComboBoxRenderer renderer;
     JTree tree;
     public ComboBoxTreeDemo()
          setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
          DefaultMutableTreeNode root =  new DefaultMutableTreeNode("top");
          DefaultMutableTreeNode sub1 =  new DefaultMutableTreeNode("sub1");
          DefaultMutableTreeNode sub2 =  new DefaultMutableTreeNode("sub2");
          root.add(sub1);
          root.add(sub2);
          tree = new JTree(root);
          String[] string = {"1" };
          JComboBox jcb = new JComboBox(string);
          renderer = new ComboBoxRenderer(this);
          jcb.setPreferredSize(new Dimension(100,22));
          jcb.setEditable(true);
          jcb.setRenderer(renderer);
          JPanel jpa = new JPanel();
          jpa.setLayout(new BoxLayout(jpa, BoxLayout.PAGE_AXIS));
          jpa.setAlignmentX(Component.LEFT_ALIGNMENT);
          jpa.add(jcb);
          add(jpa);
          setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
     private static void createAndShowGUI()
          JFrame.setDefaultLookAndFeelDecorated(true);
          JFrame frame = new JFrame("ComboBoxTreeDemo");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          JComponent newContentPane = new ComboBoxTreeDemo();
          newContentPane.setOpaque(true);
          frame.setContentPane(newContentPane);
          frame.pack();
          frame.setVisible(true);
      class ComboBoxRenderer extends JPanel implements ListCellRenderer
          ComboBoxTreeDemo cbt;
          public ComboBoxRenderer(ComboBoxTreeDemo cbt)
               this.cbt = cbt;
               setLayout(new BorderLayout());
               add(cbt.tree);
          public Component getListCellRendererComponent(JList list,Object value,int index, boolean isSelected,boolean cellHasFocus)
               return this;
     public static void main(String[] args)
          javax.swing.SwingUtilities.invokeLater(new Runnable()
               public void run()
                    createAndShowGUI();
}

Thank you for the excellent reference Peddi. I had played with the OAMessageChoiceBean component yesterday, but I was able to tell from your instructions that "Picklist Display Attribute" and "Picklist Value Attribute" really are not for binding to the database EO. That was the key piece of information that had me confused.
In addition to adding the messageChoice component to the page, I needed to write some code to synchronize the picklist value with the corresponding code value, which I placed in am OAFormValueBean (hidden form field) which I could then bind to my application's database EO in the controller, running in the processFormRequest procedure:
/** Synchronize the catalog code with the selected catalog name */
protected void syncCatalogValues(OAPageContext pageContext,
OAWebBean webBean, MyApplicationAMImpl am) {   
OAMessageChoiceBean mcb =
(OAMessageChoiceBean) webBean.findChildRecursive("CatalogName");
OAFormValueBean cc =
(OAFormValueBean) webBean.findChildRecursive("CatalogCode");
String catalogDescription = mcb.getText(pageContext);
if (catalogDescription != null) {
String catalogCode = am.getCatalogCode(catalogDescription);
cc.setValue(pageContext, catalogCode);
Along with a little code to get the catalogCode value from the LOVVO, that's all it took.
Thanks again. This was a great help.
Pete

Similar Messages

  • How can I make a bound drop-down list using OAF?

    Please note, this is for OAF. I am aware of the support in ADF.
    I'm sorry this is such a basic question, but I've been trying for days, and I can't think of anywhere else to look for an answer.
    I need a simple drop-down list, not a search. This particular list only has 10 or so items. It is based on a view containing a code value, and a description. I need all descriptions to be available at all times. Just click the arrow, and the entire list is displayed. When the user selects an entry, the code associated with the discription populates a bound attribute. Ideally, when the page is instantiated, the code value controls the text value visible in the collapsed drop-down list. Visually, it would be similar to an html <select> element.
    Can someone please tell me how I can produce such a simple thing, or point me to some documentation?
    Thank you.

    Thank you for the excellent reference Peddi. I had played with the OAMessageChoiceBean component yesterday, but I was able to tell from your instructions that "Picklist Display Attribute" and "Picklist Value Attribute" really are not for binding to the database EO. That was the key piece of information that had me confused.
    In addition to adding the messageChoice component to the page, I needed to write some code to synchronize the picklist value with the corresponding code value, which I placed in am OAFormValueBean (hidden form field) which I could then bind to my application's database EO in the controller, running in the processFormRequest procedure:
    /** Synchronize the catalog code with the selected catalog name */
    protected void syncCatalogValues(OAPageContext pageContext,
    OAWebBean webBean, MyApplicationAMImpl am) {   
    OAMessageChoiceBean mcb =
    (OAMessageChoiceBean) webBean.findChildRecursive("CatalogName");
    OAFormValueBean cc =
    (OAFormValueBean) webBean.findChildRecursive("CatalogCode");
    String catalogDescription = mcb.getText(pageContext);
    if (catalogDescription != null) {
    String catalogCode = am.getCatalogCode(catalogDescription);
    cc.setValue(pageContext, catalogCode);
    Along with a little code to get the catalogCode value from the LOVVO, that's all it took.
    Thanks again. This was a great help.
    Pete

  • How can I add categories to drop-down lists or check-boxes?

    hello can I use sub categories or group items by labels when using drop-down lists or check-boxes?

    You can't include sub-menus in a drop-down. What is possible, though, is to populate another drop-down based on the selection made in the first one, or use a pop-up menu. Both things require a script, though.

  • How can I get my Bookmark drop down list back?

    I had to clear and restore my Macbook Pro and when I installed Firefox the drop down Bookmark menu is gone. I have the same version of Firefox on two computers and one has the drop down menu and this one doesn't. How do I get it back?

    Do you mean the star on the location/address bar to bookmark the current page?
    You can try to click the Restore Defaults button in the Customize palette.
    Make sure that toolbars like the "Bookmarks Toolbar" are visible.
    *"3-bar" Firefox menu button > Customize > Show/Hide Toolbars
    *View > Toolbars<br>Tap the Alt key or press F10 to show the Menu Bar
    *Right-click empty toolbar area
    Open the Customize window and set which toolbar items to display.
    *"3-bar" Firefox menu button > Customize
    *check that "Bookmarks Toolbar items" is on the Bookmarks Toolbar
    *if "Bookmarks Toolbar items" is not on the Bookmarks Toolbar then drag it back from the Customize palette into the Customize window to the Bookmarks Toolbar
    *if missing items are in the Customize palette then drag them back from the Customize window on the toolbar
    *if you do not see an item on a toolbar and in the Customize palette then click the Restore Defaults button to restore the default toolbar setup
    *https://support.mozilla.org/kb/customize-firefox-controls-buttons-and-toolbars

  • How can I display images in drop down.

    Hi All,
    How can I display images in drop down.
    <select><option>image here</option></select>
    please reply soon.
    anser please
    Thanks

    I have not found html forum..That's just incredible.
    where can i find it ?Sorry, I'm still recovering from that remark.
    please reply soonEvery time you end a post with this, or "urgent" or other such keywords, the forum automatically introduces a 5 minute delay so that will actually make the whole process slower (not faster).

  • How can I enable the automated drop down for the subject line on the email page

    How can I enable the automated drop down for the subject line on the email page as I send more than 300 emails everyday with the same subject line. Before it use to happen in my gmail account but now its not. Please help me as its increasing my work time because I have to type the subject line again and again on each email I send. Please help me guys.

    This is usually caused by one or more bookmarks having a long title.
    You can check that folder in the Library and shorten long names.
    * Bookmarks > Show Al Bookmarks
    *Bug 626066 - History, Bookmarks menus too wide because of pages with long titles on 64bits
    <i>Please do not comment in bug reports: https://bugzilla.mozilla.org/page.cgi?id=etiquette.html</i>

  • How can I clear the browser pull down list, I have followed directions using options and it just won`t clear

    How can I clear the browser pull down list, I have followed directions using options and it just won`t clear

    Entries in the location bar drop down list with a yellow (blue on Mac) star at the right end are bookmarks.<br />
    You can remove such a bookmarked item that shows in the list if you open that url in a tab and click the yellow star in the location bar.<br />
    This will open the "Edit This Bookmark" dialog and you can click the Remove button to remove the bookmark if you want to remove such a bookmarked entry.<br />
    * [[Clearing Location bar history]]
    * [[Cannot clear Location bar history]]

  • Related Issue column in tracking list gets changed into drop down list in Infopath

    Hi All,
     i have created Tracking list in sharepoint 2010. which has column[Related issue - lookup for field in list[title] by default.
    this field will have a multiple selection check box,2 buttons [Add and remove] and text box[which show the items selected in check box].
    my issue is ,when i try to modify my list in Infopath. this column[Related issue] gets changed into drop down list item.Is is possible  to get the same [old format] back. if so pls guide me..
    I faced the same in Radio button,but i restored it by changing it into option button in Infopath
    V Jean

    Hi ,
    The
    multiple-selection list box control should be by design in InfoPath form, which is corresponding to the SharePoint "Related Issues" field, in my opinion, it cannot be converted to [old format] in InfoPath form, you may need to use SharePoint Designer 2010
    to customize your Issue Tracking list NewForm.aspx/EditForm.aspx per the way in the following article, then "Related Issues" field will still be the old format,
    http://www.cjvandyk.com/blog/Articles/How%20do%20I%20-%20Customize%20the%20NewForm.aspx%20or%20EditForm.aspx%20of%20my%20SharePoint%20list.aspx
    Thanks
    Daniel Yang
    TechNet Community Support

  • Can we assign OTR to drop down list?

    Hi, All:
    In Webdyn Pro, Can we use Text element or can we assign OTR to drop down list text field.
    for example:
    wa_value_set-text  = $OTR:ZPACKAGE/TEST_MSG
    thanks,

    STEP 1 GET THE OTR TEXTS:
    <b>
    As described in previous answer...
    CALL METHOD CL_BSP_RUNTIME=>GET_OTR_TEXT
          EXPORTING
            ALIAS = 'OTR_Package/OTR_Elemet'
          RECEIVING
            TEXT  = wa_value_set-text .
    </b>
    Step 2 Update Node attribute info with the set of
    <b>
    Update the meta data info behind the COntext Node attribute that is to have the
    drop down list.
    GET NODE from WD_CONTEXT.  (use wizard)
    Then call GET_NODE_INFO to get the reference to the meta.
    Then ADD  your values,  whatever they are from STEP 1 to the ATTRIBUTE 
    of the node. Using SET_ATTRIBUTE_VALUE_SET method.
    </b>
    Seems a strange thing to do.
    May I ask why the OTR is to be the source of drop down lists ?
    regards
    Phil.

  • How can  we put  Documents into SDN

    Hi friends,
      I have one document  about Reporting... i prepared   that with screen shots.. now i want to put into SDN .. it will be helpfull to many people..
       can any one suggest me.. how can we put  into SDN...( i mean i dont have any idea abt WIKI  and Blogs.... so,    can any one plz guide me..)
    Thanks
    AK
    null

    Hello Ajay,
    here is an <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d3522851-0e01-0010-e795-fbb9fc59c905">article about SDN documents</a>. It decribes how to <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/68f93647-0a01-0010-8891-92cea7f0313f">complete this form</a>, which has to be send to SDN. Good luck with that...
    Reward points if helpful,
    regards, Martin

  • How can you delete the automatic drop-down address in Google mail on the iPad2??

    I want to delete an e-mail address that automatically  pops up when I send from Google mail.  How can I do this? Thanks!

    Use these steps to remove saved (form) data from a drop down list:
    #Click the (empty) input field on the web page to open the drop down list
    #Highlight an entry in the drop down list
    #Press the Delete key (on Mac: Shift+Delete) to remove it.
    *http://kb.mozillazine.org/Deleting_autocomplete_entries

  • How can I put video into my ipod

    Please tell me how can I put the videos in my ipod by using itunes? I try to put the DVD but it didnt appeare in my itunes. I cant add the video to my library

    Would you happen to know what format the Music Video is that you are trying to import? iTunes can only support a few kinds: MPEG, MPEG-4, and MOV.
    Make sure you are converting the file to an iTunes compatible format.
    If it is a WMV or AVI, it will probably not work. In this case, find a third-party program to convert these files for you. Search Google for free options.

  • How to use value in a drop-down list box as "With these Values" parameter?

    Hello, new user.
    I have a drop-down list box on Page 1, upon which the user can choose a study number. The List Box is named "P1_STUDY_NBR".
    Then I have a list, one entry of which goes to my master-detail form, which is Page 6. I would like it to go to the study number that the user choose on Page 1.
    In my target on the create/edit list entry, I put in "Page in this Application", "Page 6", then in Set these items, I put in
    P6_STUDY_NBR
    My question is what to use in With these values, where I want the contents of the P1_STUDY_NBR. I tried:
    &P1_STUDY_NBR
    and that does not work. If I put in one of the study numbers, like 336-00, then it does work, but I want it to pass the study number the user chooses in the list box. How do I refer to the contents of P1_STUDY_NBR?
    -Mary

    Yes, that does work, thanks. I'm now getting the default value I was putting in yesterday rather than an error message, so there must be something loading it, but I'll hunt around for what process might be doing that, or try re-creating the master-detail form again.

  • UI - How to make Columns in a Drop Down List Selection?

    I am altering a code from Peter Kahrel "Beginning Script UI". I am trying to make a searchable drop down list that will have 4 columns. So far, the search works and I have headings in the search, but I cannot seem to make the columns for the actual data. I believe I need to change the type_ahead since the array is looking at this data. I'm stuck in the water. Can someone tell me what I need to do to get the list to show up as columns? How do I turn the picked = type_ahead data into four columns? Code and Screenshot below:
    picked = type_ahead (["bat", "bear", "beaver", "bee", "cat", "cats_and_dogs",
    "dog", "maggot", "moose", "moth", "mouse"]);
    function type_ahead (array)
    var w = new Window ("dialog", "Quick select");
    var entry = w.add ("edittext", [0, 0, 800, 22]);
    entry.active = true;
    var list = w.add ("listbox",  [0, 0,800, 500], "",
    {numberOfColumns: 4, showHeaders: true,
    columnTitles: ["Non-Approved Word", "Approved Alternative", "Approved Use", "Non-Approved Use"], columnWidths: [200,200,200,200]});
    list.selection = 0;
    entry.onChanging = function ()
    var temp = this.text;
    list.removeAll ();
    for (var i = 0; i < array.length; i++)
    if (array[i].toLowerCase().indexOf (temp) == 0)
    list.add ("item", array[i]);
    if (list.items.length > 0)
    list.selection = 0;
    entry.onChange = function () {w.close (1)}
    if (w.show () != 2)
    return list.selection.text;
    else
    w.close ();

    Hi Peter,
    This is one of those developments that push the limits of my knowledge-base and when things do that, I lose sleep until I figure it out. With that said :-) here is where I have ended up.
    Basically I made a new array for the table data.  I then use an array lookup to sort the array in the listbox based on the 0 array item. See the code below. Once it is loaded type in "b" and the list will start to sort.
    I need to try to get this to work as a pallete instead of a dialog box. Do palletes support this type of functionality?
    var newarray = new Array(
    new Array('Butterfly ','has wings','can fly'),
    new Array('bohemith moth','has wings','cannot fly very good'),
    new Array('word 3','replacement word','use case'));
    picked = type_ahead (newarray);
    function type_ahead (array)
    var w = new Window ("dialog", "STE Checker");
    var entry = w.add ("edittext", [0, 0, 800, 22]);
    entry.active = true;
    var list = w.add ("listbox",  [0, 0,800, 500], "",
    {numberOfColumns: 3, showHeaders: true,
    columnTitles: ["Column 1",  "Column 2", "Column 3" ], columnWidths: [200,200,400]});
    list.selection = 0;
    entry.onChanging = function ()
    var temp = this.text;
    list.removeAll ();
    for (var i = 0; i < array.length; i++)
    if (array[i][0].toLowerCase().indexOf (temp) == 0)
    with (list.add ("item", array[i][0]))
    subItems[0].text = array[i][1];
    subItems[1].text = array[i][2];
    if (list.items.length > 0)
    list.selection = 0;
    entry.onChange = function () {}
    if (w.show () != 2)
    return list.selection.text;
    else
    w.close ();

  • How to populate data from dynamic drop down list to the text field

    Hi,
    I tried to populate data from dynamic drop down list to city field. I would like to concat data from drop down list.When selecting add button to add the item and select item from drop down list, data should be displayed in the text field. However, Please help. I spent alot of time to make it works I am not successful.
    Please see the link below.
    https://acrobat.com/#d=SCPS0eVi6yz13ENV0cnUdw
    Thanks for your help
    Cindy

    Hi Rosalin,
    Loop the hidden table, get the values and populate drop down in each iteration.
    DropDownList1.addItem("Text","Value");
    You can use one more solution for this scenario. If it is a matter of 2,3 dropdowns, put three dropDowns in the form layout and give seperate static data binding to them. At run time make the dropDowns hide/visible as per the requirement.
    Hope this helps.
    Thanks & Regards,
    Sanoosh

Maybe you are looking for

  • How do I add Music to Gif Animations?

    If I make a gig animation in Image Ready, the only way I know how to add sound is to do it through Premiere Elements. The problem is it compresses the image so much it's unwatchable. Any Idea where I'm going wrong?

  • How Can I save and upload a Muse website as .htm files?

    I have recently updated my website www.silverdogmusic.co.uk with Adobe Muse. The problem I have is that all my lovely SEO that I have built up over the last five years is pointing at .htm and there is no way to save a .htm file extention with Muse, o

  • Delete View Cluster

    Dear all, Pls show me how to delete a View Cluster that made by Se54? Thanks, Quanglv

  • FLV in SWF in Director MX 2004 Issue

    I did a search, but couldn't find a response to this issue. I have SWF running in a sprite in Director MX 2004. The SWF includes an FLVPlayer component with a "SteelExternalPlayMute.swf" skin and links to an external FLV. (Flash files are version 8.

  • How to Finding the Last Row Value in Datagrid?

    Hi Everyone, Thanks in Advance. I need your help, to find the last row data in Datagrid. Actually i am using Datagrid to display my Data in flex. In my data i stored the gender value of employees. So if the last row in my datagrid is "female" i need