Tree in combobox

hi,
i have combobox and it shows the list of something. So what i need is to change that list to the Tree. Any ideas?

Well....
1) you could write your own component (model, listener UI, component etc.).
2) you could cheat
3) you could look for one elsewhere - e.g. search google for "JComboTree" or similar
1) Writing a new component isn't too hard. You'd be putting a JTree into a scrollpane into a popup and getting that to appear when the user clicked a button. Structuring that properly to uyse MVC would be, err, "educational".
2) Assuming you didn't want the tree to expand/collapse you could cheat by writing a list cell renderer that would put branches before the text/icon for each node. This would simply require that the renderer could determine the depth of each item in the list.
A very quick approach would be to use something like this:
public class TreeNodeListCellRenderer extends DefaultListCellRenderer {
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
        // Assumes everything in the list is some "Node" class...
        YourNode node = (YourNode)value;
        // Cheesy - convert node to string, adding on as many spaces as the node is deep in the tree
        // Obviously you'd use a StringBuffer (or have an icon of the right width in front of the text) but this should suffice to demonstrate
        String text = node.getValue().toString();
        while(node != null) {
           node = node.getParent();
           text = " " + text;
        return super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
}Hope this helps.

Similar Messages

  • [svn:fx-trunk] 10209: reverting commit 10198, which affected animation for some halo components like Tree and ComboBox.

    Revision: 10209
    Author:   [email protected]
    Date:     2009-09-12 17:36:41 -0700 (Sat, 12 Sep 2009)
    Log Message:
    reverting commit 10198, which affected animation for some halo components like Tree and ComboBox. Should wait for either the real fix (involves RPC changes) or at least a fix that limits the scope to only Flex4 effects instead of all uses of UIComponent.suspendBackgroundProcessing.
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/framework/src/mx/managers/LayoutManager.as

  • Dynamically refresh a Tree

    Hi Everybody,
    I need to get Tree nodes refreshed based on some criteria.
    The criteria will be based on a combobox or PopupMenuButton change
    event. To achieve the same, I am using a Tree control, which is
    being populated by an XMLListCollection. The XMLListcollection has
    a filterFunction that filters the tree nodes that will be
    displayed. The criteria for the filterFunction depends on a
    ComboBox selection.
    The filterFunction for the XMLListCollection is called during
    the Combo change event but the tree data is not refreshed and
    doesnot display the desired filtered result.
    I have tried doing this for a arraycollection with a datagrid
    and it works fine but doesnot work for a tree. How can we refresh
    the tree data. Below are the code snippet used to perform the Tree
    filter which is not working and not throwing any error as well.
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="vertical" creationComplete="SetFilter();"
    creationPolicy="all" >
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import flash.events.Event;
    private function SetFilter():void{
    xlc.filterFunction = treeFilter;
    private function treeFilter(item:Object):Boolean{
    var blResult:Boolean = false;
    var csProject:String = [email protected]();
    // mx.controls.Alert.show(csProject + " .. " +
    cmbTree.selectedLabel.toString());
    if(csProject.indexOf(cmbTree.selectedLabel.toString()) !=
    -1){
    blResult = true;
    return blResult;
    ]]>
    </mx:Script>
    <mx:XML id="xmldata" source="data/treedata.xml"/>
    <mx:XMLListCollection id="xlc"
    source="{xmldata.node}" filterFunction="treeFilter"/>
    <mx:Tree id="trTest" dataProvider="{xlc}"
    labelField="@label" showRoot="false">
    </mx:Tree>
    <mx:ComboBox id="cmbTree" change="xlc.refresh()">
    <mx:ArrayCollection>
    <mx:Object label="By Licensee, Project" data="By
    Licensee, Project"/>
    <mx:Object label="By Licensee, Project, File Type"
    data="By Licensee, Project, File Type"/>
    <mx:Object label="By Licensee, Date" data="By Licensee,
    Date"/>
    <mx:Object label="By Licensee, Date, Project" data="By
    Licensee, Date, Project"/>
    </mx:ArrayCollection>
    </mx:ComboBox>
    </mx:Application>
    treedata.xml file has the following data that is displayed as
    tree nodes.
    <root>
    <node label="By Licensee, Project">
    <node label="Abc">
    <node label="Mugs"/>
    <node label="Test" />
    </node>
    </node>
    <node label="By Licensee, Project, File Type">
    <node label="Abc123">
    <node label="Mugs1"/>
    <node label="Test1" />
    </node>
    </node>
    <node label="By Licensee, Date">
    <node label="Abc456">
    <node label="Mugs2"/>
    <node label="Test2" />
    </node>
    </node>
    <node label="By Licensee, Date, Project">
    <node label="Abc567">
    <node label="Mugs3"/>
    <node label="Test3" />
    </node>
    </node>
    </root>
    Please advise and suggest on where I am going wrong or if
    there is any other better way to perform the desired result.
    Thanks.
    Regards,
    Paromita

    You can not filter but can you refresh the tree control? Or
    do you have to build a new dataprovider every time ... What if you
    want to add an item to a node such as:
    tree.dataDescriptor.addChildAt(tree.selectedItem,
    {label:"topper", children:[{label:"one"}, {label:"two"}]}, 0);
    once you add the item you have to expand the node that you
    added it to ... how do you get the tree to refresh ... i have tried
    tree.validateDisplayList();
    tree.validateNow();
    treeDp.refresh();
    and my dataprovider is an ArrayCollection

  • Combo boxes with number of jtree models

    Hi
    Does anyone off hand know of a good illustrative tutorial of how to make a JComboBox control setModel on a JTree.
    The idea is so when One is selected the first TreeModel is used, when Two is selected the second and so forth.
    If anyone could steer me in the right direction it would help me a great deal at this point. Thanks.

    Here's a rather ugly example:import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.event.TreeModelListener;
    import javax.swing.tree.TreeModel;
    import javax.swing.tree.TreePath;
    public class Test extends JFrame {
        public Test() {
            super("Test");
            setContentPane(new TestPanel());
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            pack();
            setLocationRelativeTo(null);
            setVisible(true);
        private class TestPanel extends JPanel {
            private JComboBox comboBox;
            private JTree tree;
            public TestPanel() {
                tree = new JTree();
                Integer[] depths = new Integer[8];
                for (int i = 0; i < depths.length; i++) {
                    depths[i] = i;
                comboBox = new JComboBox(depths);
                comboBox.setSelectedIndex(3);
                comboBox.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        replaceTreeModel();
                replaceTreeModel();
                setLayout(new BorderLayout());
                add(new JScrollPane(tree));
                add(comboBox, BorderLayout.SOUTH);
            private void replaceTreeModel() {
                tree.setModel(new TestTreeModel((Integer) comboBox.getSelectedItem()));
        // my apologies for this tree model - I just wanted to hack something
        // together rather quickly [this doesn't look like production code :)]
        private class TestTreeModel implements TreeModel {
            private String name;
            private TestTreeModel[] children;
            public TestTreeModel(int depth) {
                this("root", 0, depth);
            private TestTreeModel(String name, int d, int depth) {
                this.name = name + " (" + d + ")";
                if (d == depth) {
                    children = new TestTreeModel[0];
                } else {
                    children = new TestTreeModel[5];
                    for (int i = 0; i < children.length; i++) {
                        children[i] = new TestTreeModel(Character.toString((char) ('a' + i)), d + 1, depth);
            public Object getRoot() {
                return this;
            public Object getChild(Object parent, int index) {
                return ((TestTreeModel) parent).children[index];
            public int getChildCount(Object parent) {
                return ((TestTreeModel) parent).children.length;
            public boolean isLeaf(Object node) {
                return getChildCount(node) == 0;
            public void valueForPathChanged(TreePath path, Object newValue) {
                // can't happen
            public int getIndexOfChild(Object parent, Object child) {
                for (int i = 0; i < getChildCount(parent); i++)
                    if (getChild(parent, i) == child)
                        return i;
                return -1;
            public void addTreeModelListener(TreeModelListener l) {
                // never changes
            public void removeTreeModelListener(TreeModelListener l) {
                // never changes
            @Override
            public String toString() {
                return name;
        public static void main(String... args) {
            new Test();
    }

  • How to change the data provider of the tree with the selection of combobox

    This is my XML data in a file named `nodesAndStuff.xml`.
        <?xml version="1.0" encoding="utf-8"?>
        <root>
            <node label="One" />
            <node label="Two" />
            <node label="Three" />
            <node label="Four" />
            <node label="Five" />
            <node label="Six" />
            <node label="Seven" />
            <node label="Eight" />
            <node label="Nine" />
        </root>
    The component using this data source is an `XMLListCollection` which is bound to a spark `ComboBox` and the code for that is:
        <s:Application name="Spark_List_dataProvider_XML_test"
            xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/halo"
            initialize="init();">
        <fx:Script>
            <![CDATA[
                private function init():void {
                    xmlListColl.source = nodes.children();
    private function closeHandler(event:Event):void {
                    myLabel.text = "You selected: " +  ComboBox(event.target).selectedItem.label;                 myData.text = "Data: " +  ComboBox(event.target).selectedItem.data;
            ]]>
        </fx:Script>
        <fx:Declarations>
            <fx:XML id="nodes" source="nodesAndStuff.xml" />
        </fx:Declarations>
        <mx:ComboBox id="cmbList" dataProvider="{ListXLC}" labelField="STOREVALUE"  close="closeHandler(event);"/>
         <s:dataProvider>
            <s:XMLListCollection id="xmlListColl" />
         </s:dataProvider>
    </mx:ComboBox>
    <mx:VBox width="250" color="0x000000">
                <mx:Text  width="200" color="blue" text="Select a type of credit card."/>
                <mx:Label id="myLabel" text="You selected:"/>
                <mx:Label id="myData" text="Data:"/>
            </mx:VBox> 
    <mx:Tree id="myTree" width="50%" height="100%" visible="false" />
    </s:Application>
    now another of my xml for example this is one.xml
    <?xml version="1.0" encoding="utf-8"?>
    <root>
        <node label="Eleven" />
        <node label="Twelve" />
        <node label="Thirteen" />
        <node label="Fourteen" />
        <node label="Fifteen" />
        <node label="Sixteen" />
        <node label="Seventeen" />
        <node label="Eightteen" />
        <node label="Nineteen" />
    </root>
    and another one is two.xml
    <?xml version="1.0" encoding="utf-8"?>
    <root>
        <node label="twety one" />
        <node label="twety two" />
        <node label="twety three" />
        <node label="twety four" />
        <node label="twety five" />
        <node label="twety six" />
        <node label="twety seven" />
        <node label="twety eight" />
        <node label="twety nine" />
    </root>
    Now I have added my tree just below the list and I have saved counting from 10 to 19 in `one.xml`, 20 to 29 in `two.xml` and so on in different XML file. I have no clue how to connect the XML containing counting from 10 to 19 as the single node in tree at the selection of label one in list and make its visiblity true.this all are dependent on combobox as on selection of item in combobox will lead to change the dataprovider of tree at runtime. i.e on selecting value one in combobox one.xml should be the data provider for tree control. Can anyone help me on this

    This is my XML data in a file named `nodesAndStuff.xml`.
        <?xml version="1.0" encoding="utf-8"?>
        <root>
            <node label="One" />
            <node label="Two" />
            <node label="Three" />
            <node label="Four" />
            <node label="Five" />
            <node label="Six" />
            <node label="Seven" />
            <node label="Eight" />
            <node label="Nine" />
        </root>
    The component using this data source is an `XMLListCollection` which is bound to a spark `ComboBox` and the code for that is:
        <s:Application name="Spark_List_dataProvider_XML_test"
            xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/halo"
            initialize="init();">
        <fx:Script>
            <![CDATA[
                private function init():void {
                    xmlListColl.source = nodes.children();
    private function closeHandler(event:Event):void {
                    myLabel.text = "You selected: " +  ComboBox(event.target).selectedItem.label;                 myData.text = "Data: " +  ComboBox(event.target).selectedItem.data;
            ]]>
        </fx:Script>
        <fx:Declarations>
            <fx:XML id="nodes" source="nodesAndStuff.xml" />
        </fx:Declarations>
        <mx:ComboBox id="cmbList" dataProvider="{ListXLC}" labelField="STOREVALUE"  close="closeHandler(event);"/>
         <s:dataProvider>
            <s:XMLListCollection id="xmlListColl" />
         </s:dataProvider>
    </mx:ComboBox>
    <mx:VBox width="250" color="0x000000">
                <mx:Text  width="200" color="blue" text="Select a type of credit card."/>
                <mx:Label id="myLabel" text="You selected:"/>
                <mx:Label id="myData" text="Data:"/>
            </mx:VBox> 
    <mx:Tree id="myTree" width="50%" height="100%" visible="false" />
    </s:Application>
    now another of my xml for example this is one.xml
    <?xml version="1.0" encoding="utf-8"?>
    <root>
        <node label="Eleven" />
        <node label="Twelve" />
        <node label="Thirteen" />
        <node label="Fourteen" />
        <node label="Fifteen" />
        <node label="Sixteen" />
        <node label="Seventeen" />
        <node label="Eightteen" />
        <node label="Nineteen" />
    </root>
    and another one is two.xml
    <?xml version="1.0" encoding="utf-8"?>
    <root>
        <node label="twety one" />
        <node label="twety two" />
        <node label="twety three" />
        <node label="twety four" />
        <node label="twety five" />
        <node label="twety six" />
        <node label="twety seven" />
        <node label="twety eight" />
        <node label="twety nine" />
    </root>
    Now I have added my tree just below the list and I have saved counting from 10 to 19 in `one.xml`, 20 to 29 in `two.xml` and so on in different XML file. I have no clue how to connect the XML containing counting from 10 to 19 as the single node in tree at the selection of label one in list and make its visiblity true.this all are dependent on combobox as on selection of item in combobox will lead to change the dataprovider of tree at runtime. i.e on selecting value one in combobox one.xml should be the data provider for tree control. Can anyone help me on this

  • Tree control with ComboBox

    Hi All,
    I have a need for a tree control which supports having a
    combobox. I've done extensive research on Google, but came up
    empty. If anyone has or can point me to any examples, it would be
    greatly appreciated.
    Thanks in advance!
    -jf

    Here's a follow-up to my first question.
    I found an example of a tree with checkboxes and set out to
    modify it so that it would fit my needs. I'm really stumped here,
    because it will render a checkbox or radio button fine, but I can't
    get it to render a combobox or button. I'd also like the combobox
    and button to be on the right side of the parent/child label, is
    that possible?
    Any help anyone can provide is greatly appreciated.
    Content of ComboBoxTreeRenderer:
    package util
    import mx.controls.Image;
    import mx.controls.Tree;
    import mx.controls.treeClasses.*;
    import mx.collections.*;
    import mx.controls.ComboBox;
    import mx.controls.Button;
    import mx.controls.RadioButton;
    import mx.controls.listClasses.*;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import mx.events.FlexEvent;
    import flash.display.DisplayObject;
    import flash.events.MouseEvent;
    import flash.xml.*;
    import mx.core.IDataRenderer;
    public class ComboBoxTreeRenderer extends TreeItemRenderer
    protected var myImage:Image;
    // set image properties
    protected var myComboBox:ComboBox;
    protected var myRadioButton:RadioButton;
    protected var myButton:Button;
    public function ComboBoxTreeRenderer ()
    super();
    mouseEnabled = false;
    override protected function createChildren():void
    super.createChildren();
    myRadioButton = new RadioButton();
    addChild(myRadioButton);
    myComboBox = new ComboBox();
    addChild(myComboBox);
    myButton = new Button();
    myButton.setStyle( "label", "Button" );
    addChild(myButton);
    override protected function
    updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    super.updateDisplayList(unscaledWidth, unscaledHeight);
    if(super.data)
    if (super.icon != null)
    myRadioButton.x = super.icon.x;
    myRadioButton.y = 2;
    super.icon.x = myRadioButton.x + myRadioButton.width + 17;
    super.label.x = super.icon.x + super.icon.width + 3;
    else
    myRadioButton.x = super.label.x;
    myRadioButton.y = 2;
    super.label.x = myRadioButton.x + myRadioButton.width + 17;
    Content of comboBoxTree_test.mxml:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    creationComplete="init();" >
    <mx:Script>
    <![CDATA[
    import mx.collections.*;
    [Bindable]
    public var treeList:XMLList =
    <>
    <folder isBranch="true" label="Branch 1" >
    <folder isBranch="false" label="Leaf 1" />
    <folder isBranch="false" label="Leaf 2" />
    </folder>
    </>;
    [Bindable]
    public var folderCollection:XMLListCollection;
    private function init() : void
    folderCollection = new XMLListCollection(treeList);
    comboBoxTree.dataProvider = folderCollection;
    ]]>
    </mx:Script>
    <mx:Tree
    id="comboBoxTree"
    itemRenderer="util.ComboBoxTreeRenderer"
    labelField="@label"
    width="100%" height="100%" >
    </mx:Tree>
    </mx:Application>
    **************************************************************

  • Combobox/Tree Hybrid preselected value

    So here's the problem.
    I'm using Kurt Mossman's TreeCombobox
    which you can view here -
    http://kmossman.blogspot.com/2007/03/blog-post.html
    and the source for which is below:
    <----------------------------------------TreeCombobox------------------------------------- --->
    <?xml version="1.0" encoding="utf-8" ?>
    <mx:ComboBox xmlns:mx="
    http://www.adobe.com/2006/mxml"
    >
    <mx:Script>
    <![CDATA[
    import mx.events.FlexEvent;
    [Bindable]
    private var _label:String;
    [Bindable]
    public var treeSelectedItem:Object;
    public function updateLabel(event:*):void{
    _label = event.currentTarget.selectedItem[this.labelField];
    treeSelectedItem = event.currentTarget.selectedItem;
    override protected function
    updateDisplayList(unscaledWidth:Number,
    unscaledHeight:Number):void
    super.updateDisplayList(unscaledWidth, unscaledHeight);
    if(dropdown && _label != null){
    text = _label;
    ]]>
    </mx:Script>
    <mx:dropdownFactory>
    <mx:Component>
    <mx:Tree change="outerDocument.updateLabel(event)"
    height="300" width="100%" />
    </mx:Component>
    </mx:dropdownFactory>
    </mx:ComboBox>
    <--------------------------------------EndTreeCombobox------------------------------------ -->
    It work's like an absolute charm until I want to load it with
    a predetermined value. Just as a combobox it will accept a
    selectedIndex property, but this alone wont do the trick as I also
    need to call the expandItem() method in the tree component.
    I've tried a few different approaches, none of which have
    worked. So I thought I'd throw it out here - Any
    suggestions?

    Hi Feng,
    i don't think it's possible to process a multi-level hierarchy like a tree-structure with the standard ComboCox-control. The only way i know to reuse an existing control in a ComboBox is the assigning of a ListBox. But then, you will also have a simple list whit a single level structure.
    Better you use the Tree or TreeTable control.
    Regards Michael

  • ComboBoxes and a Tree

    Hi,
    Well my problem comes from the same source as many of my problems, lack of understanding on how swing works and I think instead of posting what I have done and trying to fix it I am seeking for the best way to do it from scratch.
    So Im going to keep this simple and generic:
    There are so many foos in the program and each foo has so many bars.
    So what I want to do is dynamically update the first JComboBox with all the foos in the program and then when the user selects a foo I want the second jComboBox to be updated to show all the bars that foo has.
    I am also working on a JTree where it adds folders as foos and bars are created (of course bars being within the foo folders) but I think I will worry about it after I fix the JComboBoxes.
    So I tried two different methods, first using removeAllItems and then using addItem in a loop to add to the comboBox, the second was to set a new model containing an array of all the items. I have had alsorts of irratic problems but I think the main ones are the first dialog adding 2 sets of the same items until the user selects something, then its fixed. The other is that the second comboBox isnt updating correctly when something is selected in the first.
    Any ideas would be appriciated.
    Thanks,
    Ken.

    Well I use netBeans GUI builder which is the cause of alot of frustraction, I end up working around it instead of it around me and I know its not a good way too do it, I could do it all by hand but I use it purely for speed as I need all the help I can get with the limited time i have.

  • Problems with linked ComboBoxes

    Hi everyone, and thanks to those who will reply
    It's been 3 days since i'm having the same problem :
    I have 2 comboboxes in a JPanel, and the things to be displayed in the second one depends on the first (for example selecting 'Hewlett-Packard' in the first combo box display all HP model in the second one)
    When i select a item in the first combobox, an actionPerformed is fired, and i can populate the second combobox. Unfortunately, the combobox disappear in my panel, but if i click on the place where it used to be, the popup list display correctly... !
    I just want to know hox can i make it visible anyway. I've tried combobox2.repaint() method within the actionperformed method (combobox2 is the name of my second combo box as you've guessed), but it doesnt work...
    Something else too : in my first list, if i select another vendor, the list in the second is not removed, but the list of workstation of the second-select manufacturer is appended... I've tried here the combobox2.removeall() method, but here again, no results....
    this is my code :
    public class DocPCConfig extends JFrame implements ActionListener, WindowListener
    /** D�clare les variables utilis�es **/
    JComboBox comboConstructeurs, comboMachines;
    private JPanel imagePanel, panelConstructeur, panelMachines;
    * DocPCConfig()
    * Constructeur par d�faut
    * - But : Initialise les composants Swing de la fen�tre principale
    * - E : -/-
    * - S : -/-
    public DocPCConfig()
    /** Ajoute les composants dans l'onglet **/
    ajoutCompoCstr();
    /** Ajoute un �couteur d'�v�nement de fen�tre **/
    addWindowListener(this);
    * main()
    * - But : Point d'entr�e de l'application
    * - E : String args[] : Tableau de param�tres
    * - S : -/-
    public static void main(String args[])
    System.out.println("Lancement de l'application de configuration");
    new BdD();
    mainFrame = new DocPCConfig();
    mainFrame.setSize(1024,738);
    mainFrame.setTitle("DocPCConfig");
    mainFrame.setVisible(true);
    * ajoutCompoCstr()
    * - But : Ajoute les composants pour le panel de s�lection constructeur/machine (1er onglet)
    * - E : -/-
    * - S : -/-
    public void ajoutCompoCstr()
    java.awt.GridBagConstraints gridBagConstraints1;
    /** Cr�e le vecteur stockant les r�sultats provenant de la BdD **/
    Vector listeConstructeurs = new Vector(10,5);
    /** Se connecte � la BdD **/
    BdD.connecteBdD();
    /** R�cup�re la liste des constructeurs depuis la BdD **/
    listeConstructeurs = BdD.getConstructeurs();
    DefaultComboBoxModel comboModele = new DefaultComboBoxModel(listeConstructeurs);
    BdD.deconnecteBdD();
    /** Lance le constructeur pour la liste d�roulante avec le vecteur de liste
    comme param�tre **/
    comboConstructeurs = new JComboBox(comboModele);
    /** R�gle les param�tres suppl�mentaires **/
    comboConstructeurs.setMaximumSize(new Dimension(5,5));
    comboConstructeurs.setSelectedIndex(-1);
    // comboConstructeurs.setEditable(true);
    /** Ajoute les contraintes graphiques pour la liste des constructeurs **/
    gridBagConstraints1 = new GridBagConstraints();
    gridBagConstraints1.gridx = 1;
    gridBagConstraints1.gridy = 1;
    gridBagConstraints1.insets = new Insets(10, 10, 10, 10);
    panelConstructeur.add(comboConstructeurs, gridBagConstraints1);
    comboConstructeurs.addActionListener(this);
    /** Cr�e les �l�ments de la liste d�roulante **/
    String[] listeMachines = { "                             " };
    comboMachines = new JComboBox(listeMachines);
    comboMachines.setSelectedIndex(0);
    /** Ajoute les contraintes graphiques pour la liste des machines **/
    gridBagConstraints1 = new GridBagConstraints();
    gridBagConstraints1.gridx = 1;
    gridBagConstraints1.gridy = 2;
    gridBagConstraints1.insets = new Insets(10, 10, 10, 10);
    panelConstructeur.add(comboMachines, gridBagConstraints1);
    * actionPerformed(ActionEvent ae)
    * - But : Traiter les op�ration quand une action est effectu�e sur les boutons
    * de l'interface de la fen�tre principale.
    * - E : ActionEvent ae : Un pointeur sur l'action courante.
    * - S :-/-
    public void actionPerformed(ActionEvent ae)
    Object source = ae.getSource();
    /** Liste d�roulante des constructeurs **/
    if (source == comboConstructeurs)
    /** R�cup�re la ligne s�lectionn�e dans la liste **/
    String constructeur = (String)comboConstructeurs.getSelectedItem();
    /** Creation des �l�ments de la liste d�roulante **/
    Vector listeMachines = new Vector(50,1);
    /** Se connecte � la BdD **/
    BdD.connecteBdD();
    listeMachines = BdD.getMachines(constructeur);
    /** Se d�connecte de la BdD **/
    BdD.deconnecteBdD();
    /** Supprime toutes les pr�c�dentes entr�es de la liste des machines **/
    comboMachines.removeAll();
    int i = 0;
    System.out.println(listeMachines.size());
    /** Tant que la liste n'a pas �t� parcourue **/
    while(i < listeMachines.size())
    /** Copie l'�l�ment du vecteur et l'ajoute dans la liste d�roulante **/
    comboMachines.addItem(listeMachines.elementAt(i).toString());
    i++;
    comboMachines.repaint();
    I've removed all the things I found useless, but maybe i've removed too much ;-) I hope that this code is enough.
    Thanks for your help (can you send a copy of your answers at : [email protected] - if you're too lazy to do this that's not a matter, but i don't know how i can find my post in all these posts... so that'd be cool ;-)

    Thanks Martin
    that makes sense now was driving me mad as I couldnt find anything saying it wasnt supported, makes sense seeing as its a flash server. Annoyning thing was it was playing in the content viewer locally when I previewd the folio you would think that would not be the case if it was not supported. Im going to try the rtmp links in a player in a web page and view it on the ipad out of curiosity and ill let you know. Out of interest have you done anyting with imported html into indesign as part of your folios ? I havent as yet but am curious to know how it holds up ?
    Thanks again
    Neil

  • Label display issue in Tree component when it is having vertical scrollbar

    I am using tree component as dropdown factory for combo box. When i open dropdown, it doesn't have vertical scrollbar and all the root nodes are getting displayed correctly(in closed mode). Now if i try to open any node, i am getting vertical scrollbar as the child nodes are more. Now the problem is if scroll down, some of the nodes(labels) are not getting displayed but i am able to see the icon. If i keep on scrolling bottom to top and top to bottom, some of the nodes are showing labels and some are not(It is inconsistant).
    I have not used any custom item renderer for tree control. I used my custom dataDescriptor which i have implemented from ITreeDataDescriptor. Also I tried extending DefalutDataDescriptor, but no luck.

    Does it work if the tree is not in a combobox?

  • Dynamic Creation of Objects using Tree Control

    I am able to Create Dynamic Objets using List control in
    flex,but not able to create objects using TreeControl,currently iam
    using switch case to do that iam embedding source code please help
    me how to do that
    <?xml version="1.0" encoding="utf-8"?>
    <!--This Application Deals With How to Create Objects
    Dynamically -->
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:XML id="treeDP">
    <node label="Controls">
    <node label="Button"/>
    <node label="ComboBox"/>
    <node label="ColorPicker"/>
    <node label="Hslider"/>
    <node label="Vslider"/>
    <node label="Checkbox"/>
    </node>
    </mx:XML>
    <mx:Script>
    <![CDATA[
    import mx.core.UIComponentGlobals;
    import mx.containers.HBox;
    import mx.controls.*;
    import mx.controls.VSlider;
    import mx.controls.Button;
    import mx.controls.Alert;
    import mx.core.UIComponent;
    import mx.controls.Image;
    import mx.managers.DragManager;
    import mx.events.DragEvent;
    import mx.controls.Tree;
    import mx.core.DragSource
    import mx.core.IFlexDisplayObject;
    /*This function accepts the item as on when it is dragged
    from tree Component */
    private function ondragEnter(event:DragEvent) : void
    if (event.dragSource.hasFormat("treeItems"))
    DragManager.acceptDragDrop(Canvas(event.currentTarget));
    DragManager.showFeedback(DragManager.COPY);
    return;
    else{
    DragManager.acceptDragDrop(Canvas(event.currentTarget));
    return;
    /*This Function creates objects as the items are Dragged
    from the TreeComponent
    And Creates Objects as and When They Are Dropped on the
    Container */
    private function ondragDrop(event:DragEvent) : void
    if (event.dragSource.hasFormat("treeItems"))
    var items:Array =event.dragSource.dataForFormat("treeItems")
    as Array;
    for (var i:int = items.length - 1; i >= 0; i--)
    switch(items
    [email protected]())
    case "Button":
    var b:Button=new Button();
    b.x = event.localX;
    b.y = event.localY;
    b.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    myCanvas.addChild(b);
    break;
    case "ComboBox":
    var cb:ComboBox=new ComboBox();
    myCanvas.addChild(cb);
    cb.x = event.localX;
    cb.y = event.localY;
    cb.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    break;
    case "ColorPicker":
    var cp:ColorPicker=new ColorPicker();
    myCanvas.addChild(cp);
    cp.x = event.localX;
    cp.y = event.localY;
    cp.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    break;
    case "Vslider":
    var vs:VSlider=new VSlider();
    myCanvas.addChild(vs);
    vs.x = event.localX;
    vs.y = event.localY;
    vs.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    break;
    case "Hslider":
    var hs:HSlider=new HSlider();
    myCanvas.addChild(hs);
    hs.x = event.localX;
    hs.y = event.localY;
    hs.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    break;
    case "Checkbox":
    var check:CheckBox=new CheckBox();
    myCanvas.addChild(check);
    check.x = event.localX;
    check.y = event.localY;
    check.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    break;
    else {
    var Component:UIComponent =
    event.dragSource.dataForFormat("items") as UIComponent ;
    Component.x = event.localX;
    Component.y = event.localY;
    Component.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    myCanvas.addChild(Component);
    /*How to move the Objects within the Container */
    public function mouseMoveHandler(event:MouseEvent):void{
    var
    dragInitiator:UIComponent=UIComponent(event.currentTarget);
    var ds:DragSource = new DragSource();
    ds.addData(dragInitiator,"items")
    DragManager.doDrag(dragInitiator, ds, event);
    ]]>
    </mx:Script>
    <mx:Tree dataProvider="{treeDP}" labelField="@label"
    dragEnabled="true" width="313" left="0" bottom="-193" top="0"/>
    <mx:Canvas id="myCanvas" dragEnter="ondragEnter(event)"
    dragDrop="ondragDrop(event)" backgroundColor="#DDDDDD"
    borderStyle="solid" left="321" right="-452" top="0"
    bottom="-194"/>
    </mx:Application>
    iwant to optimize the code in the place of switch case
    TextText

    Assuming your objects are known and what you need are simply
    variable names created by the program, try using objects as
    associative arrays:
    var asArray:Object = new Object();
    for (var n:int = 0; n < 10; n++) {
    asArray["obj" + n] = new WHAT_EVER();

  • Adding custom combobox to my scene7 tab in contentfinder

    I am trying to add custom combobox by extending the OOB scene7 contentfinder in CQ. But for some reason, I am not seeing my combo box (id and selected value) getting passed in the  request header as query parameter. Following is the js code I am using, has anyone worked on such a customization?
    =================================================
    CQ.Ext.ns("MyClientlib");
    MyClientlib.ContentFinder = {
        TAB_S7_BROWSE : "cfTab-S7Browse",
        S7_QUERY_BOX: "cfTab-S7Browse-Tree",
        CONTENT_FINDER_TAB: 'contentfindertab',
        S7_RESULTS_BOX: "cfTab-S7Browse-resultBox",
        addPageFilters: function(){
            var tab = CQ.Ext.getCmp(this.TAB_S7_BROWSE);
            var queryBox = CQ.Ext.getCmp(this.S7_QUERY_BOX);
            queryBox.add({
                "xtype": "label",
                "text": "Select Path",
                "cls": "x-form-field x-form-item-label"
            var metaCombo = new CQ.Ext.form.ComboBox({
            typeAhead: true,
            triggerAction: 'all',
            lazyRender:true,
            mode: 'local',
            store: new CQ.Ext.data.ArrayStore({
                id: "cfTab-s7Browse-metaDataStore",
                fields: [
                    'myId',
                    'displayText'
                data: [[1, 'Name'], [2, 'Keywords'], [3, 'Description']]
            valueField: 'myId',
            displayField: 'displayText',
                listners: {
                    select: function (combo, record, index) {
                                        var store = CQ.Ext.getCmp(this.S7_RESULTS_BOX).items.get(0).store;
                                                                                              store.setBaseParam("mFilter",CQ.Ext.getCmp(" cfTab-s7Browse-metaDataStore").getValue());
                                                                // CQ.S7.setSearchQualifiers(store);
                                        store.reload();
                        queryBox.add(metaCombo);
                  var cfTab = queryBox.findParentByType(this.CONTENT_FINDER_TAB);
        queryBox.add(new CQ.Ext.Panel({
                border: false,
                height: 40,
                items: [{
                    xtype: 'panel',
                    border: false,
                    style: "margin:10px 0 0 0",
                    layout: {
                        type: 'hbox'
                    items: [{
                        xtype: "button",
                        text: "Search",
                        width: 60,
                        tooltip: 'Search',
                        handler: function (button) {
                            var params = cfTab.getParams(cfTab);
                            cfTab.loadStore(params);
                        baseCls: "non-existent",
                        html:"<span style='margin-left: 10px;'></span>"
                        xtype: "button",
                        text: "Clear",
                        width: 60,
                        tooltip: 'Clear the filters',
                        handler: function (button) {
                            $.each(cfTab.fields, function(key, field){
                                field[0].setValue("");
            queryBox.setHeight(230);
                  queryBox.doLayout();
            var form = cfTab.findByType("form")[0];
            cfTab.fields = CQ.Util.findFormFields(form);
    changeResultsStore: function(){
            var queryBox = CQ.Ext.getCmp(this.S7_RESULTS_BOX);
            var resultsView = queryBox.ownerCt.findByType("dataview");
            var rvStore = resultsView[0].store;
            rvStore.proxy = new CQ.Ext.data.HttpProxy({
                url: CQ.S7.getSelectedConfigPath() + "/jcr:content.search.json",
                method: 'GET'
    (function(){
        var INTERVAL = setInterval(function(){
            var c = MyClientlib.ContentFinder;
            var tabPanel = CQ.Ext.getCmp(CQ.wcm.ContentFinder.TABPANEL_ID);
            if(tabPanel){
                clearInterval(INTERVAL);
                c.addPageFilters();
                //CQ.Ext.Msg.alert('meta','CQ.Ext.getCmp("cfTab-s7Browse-metaDataStore").getValue()');
                c.changeResultsStore();
        }, 250);
    =================================================

    Hi Aanchal,
    i have posted exactly the same problem a few months ago, and no one answered me.
    I couldn't find any documentation on how to add custom GP parameters in the universal worklist, in the examples on customizing the UWL XML they always refer to parameters from the r/3 webflow, never GP.
    I really can't believe that nobody ever tried to do this and faced this problem!
    Please let me know if you find something..
    Regards,
    Marco.

  • Combobox (Editor) and IP Address

    Hi,
    I wish to display the structure of and IP address in my ComboBox (editable) and display plus forcing user to input only digits for those 4 parts of the IP address.
    So display of a blank IP initially will be
    [    .    .    .    ]I was thinking of creating an editor, but haven't got a clue how those methods could be implemented to achieve the above.
    public interface ComboBoxEditor {
      /** Return the component that should be added to the tree hierarchy for
        * this editor
      public Component getEditorComponent();
      /** Set the item that should be edited. Cancel any editing if necessary **/
      public void setItem(Object anObject);
      /** Return the edited item **/
      public Object getItem();
      /** Ask the editor to start editing and to select everything **/
      public void selectAll();   
      /** Add an ActionListener. An action event is generated when the edited item changes **/
      public void addActionListener(ActionListener l);
      /** Remove an ActionListener **/
      public void removeActionListener(ActionListener l);
    }Do you know how this could be achieve?
    Thanks in advance.

    Hi
    This sample may helps you...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    * CustomComboBoxDemo.java is a 1.4 application that uses the following files:
    *   images/Bird.gif
    *   images/Cat.gif
    *   images/Dog.gif
    *   images/Rabbit.gif
    *   images/Pig.gif
    public class CustomComboBoxDemo extends JPanel {
        ImageIcon[] images;
        String[] petStrings = {"Bird", "Cat", "Dog", "Rabbit", "Pig"};
         * Despite its use of EmptyBorder, this panel makes a fine content
         * pane because the empty border just increases the panel's size
         * and is "painted" on top of the panel's normal background.  In
         * other words, the JPanel fills its entire background if it's
         * opaque (which it is by default); adding a border doesn't change
         * that.
        public CustomComboBoxDemo() {
            super(new BorderLayout());
            //Load the pet images and create an array of indexes.
            images = new ImageIcon[petStrings.length];
            Integer[] intArray = new Integer[petStrings.length];
            for (int i = 0; i < petStrings.length; i++) {
                intArray[i] = new Integer(i);
                images[i] = createImageIcon("images/" + petStrings[i] + ".gif");
                if (images[i] != null) {
                    images.setDescription(petStrings[i]);
    //Create the combo box.
    JComboBox petList = new JComboBox(intArray);
    ComboBoxRenderer renderer= new ComboBoxRenderer();
    renderer.setPreferredSize(new Dimension(200, 130));
    petList.setRenderer(renderer);
    petList.setMaximumRowCount(3);
    //Lay out the demo.
    add(petList, BorderLayout.PAGE_START);
    setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
    java.net.URL imgURL = CustomComboBoxDemo.class.getResource(path);
    if (imgURL != null) {
    return new ImageIcon(imgURL);
    } else {
    System.err.println("Couldn't find file: " + path);
    return null;
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("CustomComboBoxDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create and set up the content pane.
    JComponent newContentPane = new CustomComboBoxDemo();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    class ComboBoxRenderer extends JLabel
    implements ListCellRenderer {
    private Font uhOhFont;
    public ComboBoxRenderer() {
    setOpaque(true);
    setHorizontalAlignment(CENTER);
    setVerticalAlignment(CENTER);
    * This method finds the image and text corresponding
    * to the selected value and returns the label, set up
    * to display the text and image.
    public Component getListCellRendererComponent(
    JList list,
    Object value,
    int index,
    boolean isSelected,
    boolean cellHasFocus) {
    //Get the selected index. (The index param isn't
    //always valid, so just use the value.)
    int selectedIndex = ((Integer)value).intValue();
    if (isSelected) {
    setBackground(list.getSelectionBackground());
    setForeground(list.getSelectionForeground());
    } else {
    setBackground(list.getBackground());
    setForeground(list.getForeground());
    //Set the icon and text. If icon was null, say so.
    ImageIcon icon = images[selectedIndex];
    String pet = petStrings[selectedIndex];
    setIcon(icon);
    if (icon != null) {
    setText(pet);
    setFont(list.getFont());
    } else {
    setUhOhText(pet + " (no image available)",
    list.getFont());
    return this;
    //Set the font and text when no image was found.
    protected void setUhOhText(String uhOhText, Font normalFont) {
    if (uhOhFont == null) { //lazily create this font
    uhOhFont = normalFont.deriveFont(Font.ITALIC);
    setFont(uhOhFont);
    setText(uhOhText);

  • Using ComboBox as an editor for treenodes

    I have a customized combobox editor for editing treenodes. The treenodes may or may not editable based on a particular condition in the userobject at each node.
    The node and the combobox are rendered fine but as soon as I select an item from the combobox, i see the following error messages in the stack trace and the code goes into an infinite loop :
    Exception occurred during event dispatching:
    java.lang.StackOverflowError
         at java.lang.ref.Reference.<init>(Reference.java:198)
         at java.lang.ref.FinalReference.<init>(FinalReference.java:19)
         at java.lang.ref.Finalizer.<init>(Finalizer.java:69)
         at java.lang.ref.Finalizer.register(Finalizer.java:75)
         at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:883)
         at javax.swing.JComboBox.contentsChanged(JComboBox.java:950)
         at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:79)
         at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:86)

    Here's the code for the custom combobox editor:
    public class ScmComboBoxEditor extends DefaultCellEditor
    private JTree m_tree;
    /* private JComboBox m_comboBox;
    protected EventListenerList _treeNodeListeners = new EventListenerList();
    protected ChangeEvent changeEvent = null;
    public ScmComboBoxEditor(JTree tree, JComboBox combo)
    super(combo);
    m_tree = tree;
    setClickCountToStart(3);
    public Component getTreeCellEditorComponent(JTree tree, Object value,
                                  boolean isSelected,
                                  boolean expanded,
                                  boolean leaf, int row)
    Component comp = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
    if(comp instanceof JComboBox)
    JComboBox combo = (JComboBox)comp;
    ScmTreeNode thisNode = (ScmTreeNode)value;
    /* if(thisNode.getUserObject() instanceof ScmObject)
    ScmObject thisObj = (ScmObject)thisNode.getUserObject();
    Vector vItems = new Vector();
    vItems.addElement(thisObj);
    for(int j = 0; j < 3; j++)
    ScmObject obj = new ScmObject();
    obj.setName("Branch" + (j+1));
    vItems.addElement(obj);
    DefaultComboBoxModel comboModel = new DefaultComboBoxModel(vItems);
    combo.setModel(comboModel);
    if(thisNode.getUserObject() instanceof MappableProject)
    MappableProject thisObj = (MappableProject)thisNode.getUserObject();
    if(thisObj.hasBranches())
    Vector vItems = new Vector();
    vItems.addElement(thisObj);
    for(int j = 0; j < 3; j++)
    MappableProject obj = new MappableProject();
    obj.setName("Branch" + (j+1));
    vItems.addElement(obj);
    DefaultComboBoxModel comboModel = new DefaultComboBoxModel(vItems);
    combo.setModel(comboModel);
    else if(thisNode.getUserObject() instanceof MappableFolder)
    MappableFolder thisObj = (MappableFolder)thisNode.getUserObject();
    if(thisObj.hasBranches())
    Vector vItems = new Vector();
    vItems.addElement(thisObj);
    for(int j = 0; j < 3; j++)
    MappableProject obj = new MappableProject();
    obj.setName("Branch" + (j+1));
    vItems.addElement(obj);
    DefaultComboBoxModel comboModel = new DefaultComboBoxModel(vItems);
    combo.setModel(comboModel);
    return comp;
    public boolean isCellEditable(EventObject ev)
    boolean rv = false;
    if(ev instanceof MouseEvent)
    MouseEvent me = (MouseEvent)ev;
    System.out.println("Clicks = " + me.getClickCount());
    if(me.getClickCount() == this.getClickCountToStart())
    TreePath path = m_tree.getPathForLocation(me.getX(), me.getY());
    ScmTreeNode node = (ScmTreeNode)path.getLastPathComponent();
    if(((ScmObject)node.getUserObject()).hasBranches())
    rv = true;
    return rv;
    public boolean stopCellEditing()
    this.fireEditingStopped();
    return false;
    public void cancelCellEditing()
    this.fireEditingCanceled();
    /* public void addCellEditorListener(CellEditorListener l)
    _treeNodeListeners.add(CellEditorListener.class, l);
    public void removeCellEditorListener(CellEditorListener l)
    _treeNodeListeners.remove(CellEditorListener.class, l);
    protected void fireEditingStopped()
    Object[] listeners = _treeNodeListeners.getListenerList();
    for(int i = listeners.length-2; i >= 0; i-=2)
    if(changeEvent == null)
    changeEvent = new ChangeEvent(this);
    ((CellEditorListener)listeners[i+1]).editingStopped(changeEvent);
    protected void fireEditingCanceled()
    Object[] listeners = _treeNodeListeners.getListenerList();
    for(int i = listeners.length-2; i >= 0; i-=2)
    if(changeEvent == null)
    changeEvent = new ChangeEvent(this);
    ((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent);
    public void setCellEditorValue(Object value)
    m_comboBox = (JComboBox)this.editorComponent;
    m_comboBox.setSelectedItem(value);
    }

  • JTree: How to set different cell editor for different tree Nodes.

    I have a JTree and I want to set different cell editors for different node depending on some condition. E.g. I want to set ComboBox as editor for leaf node but each leaf node will have its own set of data.
    Any help or pointer?
    Thanks in advance
    Sachin

    take there:
    http://www.mutualinstrument.com/Easy/FAQ/Tree/tree.html

Maybe you are looking for