ComboBox with checkbox

Hi all

I want to display a combobox with the ablity to select multiple items and also be able to show the elements selected with different visual effects - I think that a checkbox to display selected/United Nations-selected item is more appropriate, but I can live with the alternative, like for example, highlight them selected with 'light green' etc.

Is it possible to do so under JavaFX?

Thank you

DP

import java.util.Arrays;
import java.util.List;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.ListView;
import javafx.scene.control.MenuButton;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class MultipleSelectionDropdownTest extends Application {

    @Override
    public void start(Stage primaryStage) {
        final MenuButton choices = new MenuButton("Fruit");
        final List checkItems = Arrays.asList(
            new CheckMenuItem("Apples"),
            new CheckMenuItem("Oranges"),
            new CheckMenuItem("Pears"),
            new CheckMenuItem("Grapes"),
            new CheckMenuItem("Mangoes")
        );
        choices.getItems().addAll(checkItems);

          // Keep track of selected items
        final ListView selectedItems = new ListView<>();
        for (final CheckMenuItem item : checkItems) {
            item.selectedProperty().addListener(new ChangeListener() {
                @Override
                public void changed(ObservableValue obs,
                        Boolean wasPreviouslySelected, Boolean isNowSelected) {
                    if (isNowSelected) {
                        selectedItems.getItems().add(item.getText());
                    } else {
                        selectedItems.getItems().remove(item.getText());
                    }
                }
            });
        }

        BorderPane root = new BorderPane();
        root.setTop(choices);
        root.setCenter(selectedItems);
        primaryStage.setScene(new Scene(root, 600, 400));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Tags: Java

Similar Questions

  • I created a form with checkboxes.  A question has two boxes for a 'yes' another being a 'no '.  I just want to be able to select a single box, but currently, I choose both

    I created a form with checkboxes, I have currently two checkboxes in a question that I wish I could only check a box and make it mandatory that should be checked only one box.  Currently, I am able to select the two check boxes.

    Give them the same field name, but export values.

  • ComboBox with customized with buttons listcell

    Hi all

    I would like to create a combobox with a custom listview that contains several controls. The thing is that setAction is consumed by the list of ComboBox popoup and then controls inside are ignored.

    There is here an example:

    //***************************************************************************************************************

    package javafxapplication3;

    Import javafx.application.Application;

    Import javafx.collections.FXCollections;

    Import javafx.collections.ObservableList;

    Import javafx.event.ActionEvent;

    Import javafx.event.EventHandler;

    Import javafx.scene.Scene;

    Import javafx.scene.control.Button;

    Import javafx.scene.control.ComboBox;

    Import javafx.scene.control.ListCell;

    Import javafx.scene.control.ListView;

    Import javafx.scene.input.MouseEvent;

    Import javafx.scene.layout.HBox;

    Import javafx.scene.layout.HBoxBuilder;

    Import javafx.scene.layout.StackPane;

    Import javafx.stage.Stage;

    Import javafx.util.Callback;

    SerializableAttribute public class JavaFXApplication3 extends Application {}

    @Override

    {} public void start (point primaryStage)

    ObservableList < String > options

    = (FXCollections.observableArrayList)

    "Option 1"

    'Option 2 '.

    );

    ComboBox < String > comboB = new ComboBox <>(options);

    Object obj = comboB.getOnAction ();

    comboB.setCellFactory (new reminder < < String > ListView, ListCell < String > > () {})

    @Override

    public ListCell < String > call (ListView < String > param) {}

    last cell ListCell < String > = new ListCell < String > () {}

    {

    super.setPrefWidth (100);

    }

    @Override

    {} public Sub updateItem (empty string element, Boolean)

    super.updateItem point, empty;

    If (item! = null) {}

    setText (item);

    HBox cell = HBoxBuilder.create () .children (createButton (), createButton () infrastructure ();

    setGraphic (cell);

    } else {}

    setText (null);

    }

    }

    };

    return the cell;

    }

    });

    Root StackPane = new StackPane();

    root.getChildren () .add (comboB);

    Scene = new scene (root, 300, 250);

    primaryStage.setTitle ("Hello World!");

    primaryStage.setScene (scene);

    primaryStage.show ();

    }

    private Button createButton() {}

    last button btn = new Button ("Hola");

    btn.setOnAction (new EventHandler < ActionEvent > () {}

    @Override

    {} public void handle (ActionEvent t)

    System.out.println ("Does´t work");

    }

    });

    btn.setOnMouseEntered (new EventHandler < MouseEvent > () {}

    @Override

    {} public void handle (MouseEvent t)

    System.out.println ("Works");

    }

    });

    return btn;

    }

    Public Shared Sub main (String [] args) {}

    Launch (args);

    }

    }

    //***************************************************************************************************************

    How could I do 'System.out.println ("work of Does´t");' works?

    A ComboBox control is used to select an element; from a set of predefined items (displayed in the context menu), or possibly by entering one. You intend something must be selected in your control? If so, it is not clear if something should be selected when the user presses the button. If this isn't the case, then a ComboBox control is not the appropriate control. Something like a menu button can work better.

    Assuming you want to use it to make a selection, a menu button might work if you used CustomMenuItems points the menu button and hideOnClick set to false:

    import java.util.Arrays;
    import java.util.List;
    
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.CustomMenuItem;
    import javafx.scene.control.Label;
    import javafx.scene.control.MenuButton;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.HBox;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class ButtonInMenuButtonItem extends Application {
    
        @Override
        public void start(Stage primaryStage) {
            List options = Arrays.asList("Option 1", "Option 2");
            MenuButton menuButton = new MenuButton("Options");
            for (String option : options) {
                menuButton.getItems().add(createCustomMenuItem(option));
            }
            StackPane root = new StackPane();
            root.getChildren().add(menuButton);
            Scene scene = new Scene(root, 300, 250);
            primaryStage.setTitle("Hello World!");
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    
        private CustomMenuItem createCustomMenuItem(String option) {
            HBox hbox = new HBox(5);
            hbox.getChildren().addAll(createButton(), createButton(), new Label(option));
            CustomMenuItem customMenuItem = new CustomMenuItem(hbox);
            customMenuItem.setHideOnClick(false);
            return customMenuItem ;
        }
    
        private Button createButton() {
            final Button btn = new Button("Hola");
            btn.setOnAction(new EventHandler() {
                @Override
                public void handle(ActionEvent t) {
                    System.out.println("Button pressed");
                }
            });
    //        btn.setOnMouseEntered(new EventHandler() {
    //            @Override
    //            public void handle(MouseEvent t) {
    //                System.out.println("Works");
    //            }
    //        });
            return btn;
        }
    
        public static void main(String[] args) {
            launch(args);
        }
    }
    

    If you do not want 'selection '. You should maybe use a button from menu above and manage the selection yourself.

  • Creation of ComboBox with the values of the fields

    Hey everyone, it's been a while since my last post.

    I spent some time trying to fill a ComboBox with the values of the 3 fields of different form of google and I was wondering if someone could tell me on common sense.

    Thanks a lot for any idea!

    the general idea would be something like this:

    Get added to a table field values

    var aItems = [];

    aItems.push (getField("Text1").valueAsString);

    aItems.push (getField("Text2").valueAsString);

    aItems.push (getField("Text3").valueAsString);

    Fill the drop-down list with the elements box

    getField("combo1").setItems (aItems);

    Replace domain names with real field names that you use.

    You can start the list with an element that is a single space (if it appears empty) or something like "- select -". You can also make sure you add all the duplicate entries, which would happen if all the field values are the same.

    When did you want this script to run?

  • ComboBox with customized view plugin

    Hello

    I used the plugin "Combobox with Custom Display".

    I have similar question

    When I entered the text in the textbox and scroll down using the keyboard button. The party highlight cannot scrolling with scroll.

    The demo link for above question

    http://Apex.Oracle.com/pls/Apex/f?p=35538:4

    kindly help me.

    Thank you

    Shiv says:
    Hello

    I used the plugin "Combobox with Custom Display".

    I have similar question

    When I entered the text in the textbox and scroll down using the keyboard button. The party highlight cannot scrolling with scroll.

    The demo link for above question

    http://Apex.Oracle.com/pls/Apex/f?p=35538:4

    kindly help me.

    Thank you

    Its a bug in the code of the plugin and not related to the APEX.

    I will study the issue and fix my code to resolve this problem, please bookmark this page http://www.apex-plugin.com/oracle-apex-plugins/item-plugin/combobox-with-custom-display_212.html and search for updates.

    Thank you
    Vikram

  • ADF table with checkbox refresh data binding problem

    Hello.

    I use JDeveloper 11.1.1.3. I need to use the table with checkboxes in each row of the table in my project. I use VO with transitional 'Selected' attribute that has a boolean type.
    Everything works well, wait one thing:
    When you click checbox with valueChangeListener and try to get the selected line in the managedBean you won't get any selected lines. After selecting second maaged bean evil shows that 1 single line is selected. It's my managedBean method:

    public void SelectCountyClick (ValueChangeEvent valueChangeEvent) {}

    DCIteratorBinding it = ADFUtils.findIterator (ITERATOR_NAME);

    int selectedRowCount = 0;
    RowSetIterator laughs = it.getRowSetIterator ();
    Line r = rit.first ();
    If (r! = null) {}
    If ((Boolean) r.getAttribute ("Selected"))
    selectedRowCount ++;
    }

    While (rit.hasNext ()) {}
    r = rit.next ();
    If ((Boolean) r.getAttribute ("Selected"))
    selectedRowCount ++;
    }

    System.out.println ("selected all THE LINES:" + selectedRowCount);


    }

    I tried to change this event to the client event, I got the line number, I put 'true' or 'false' to the code data binding, but whenever I can't correct data after the value change event.

    Please help me.

    The latest idea is updated databing after click of checkbox, I think. Please help me.

    Thank you!

    You must go through the concepts of life cycle of page ADF. In simple terms the Boolean value in the model is not defined in valueChangeListener. Try adding (.processUpdates) valueChangeEvent.getComponent (FacesContext.getCurrentInstance ()); on top of your listener method and see the effect.

    Reference:
    http://docs.Oracle.com/CD/E15051_01/Web.1111/b31974/adf_lifecycle.htm

  • Creating a ComboBox with ActionScript

    I can't create a ComboBox with ActionScript. I want just a simple list, I can add and subtract.

    My Code:

    var inventory: ComboBox = new more.

    Error messages:

    Scene 1, Layer ' Layer 1 ', 1 environment, line 142 1046: Type was not found or is not a constant of compilation: ComboBox. "

    Scene 1, Layer ' Layer 1 ', 1 environment, line 142 1180: call to a method may not set ComboBox. "

    I don't know where I am going wrong. I found several example on the net which was code similar to mine, and some suggested adding the following:

    import fl.controls.ComboBox;

    That didn't work either and gave me more errors. Any suggetions?

    Thanks.

    I should have mentioned to keep this import line.

  • Spark Combobox with dataprovider is empty

    There seems to be a bug when using a candle with an empty dataprovider combobox.  The idea is to have an empty combobox that adds all entries in the dataprovider for each group entered.  Attached is a simple project to demonstrate.  The first combobox has a dataprovider to the color 'Red', 'green', 'Blue' in it.  No matter what type in the box, whether it's an existing element or a new one, it displays in the label below.

    The second combobox has a dataprovider that is currently empty.  Anything by typing in the box and pressing on enter does absolutely nothing.  There is no way to get the value entered in the combobox control now.

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
          xmlns:s="library://ns.adobe.com/flex/spark" 
          xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
     <fx:Declarations>
      <!-- Place non-visual elements (e.g., services, value objects) here -->
     </fx:Declarations>
     <s:Panel x="10" y="10" width="250" height="200" title="Combobox with dataprovider">
      <s:ComboBox x="10" y="10" width="228" id="cbFull">
       <s:dataProvider>
        <s:ArrayCollection>
         <fx:String>Red</fx:String>
         <fx:String>Green</fx:String>
         <fx:String>Blue</fx:String>
        </s:ArrayCollection>
       </s:dataProvider>
      </s:ComboBox>
      <s:Label x="7" y="37" text="Selected Item: "/>
      <s:Label x="94" y="37" text="{cbFull.selectedItem}"/>
     </s:Panel>
     <s:Panel x="268" y="10" width="250" height="200" title="Combobox with empty dataprovider">
      <s:ComboBox x="10" y="10" width="228" id="cbEmpty">
       <s:dataProvider>
        <s:ArrayCollection/>
       </s:dataProvider>
      </s:ComboBox>
      <s:Label x="15" y="41" text="Selected Item: "/>
      <s:Label x="102" y="41" text="{cbEmpty.selectedItem}"/>
     </s:Panel>
    </s:Application>

    Fill out a bug with your test case report.

  • ComboBox with default selected item

    Hello

    I try to view combobox with an item selected by default. Is it possible to use instead of selectedIndex selectedItem to achieve?

    Here is the code and I want User2 to be selected by default:

    <? XML version = "1.0" encoding = "utf-8"? >
    " < = xmlns:mx mx:Application ' http://www.Adobe.com/2006/MXML "layout ="absolute"xmlns:local =" * "> "
    < mx:HBox id = "box" >
    < text mx:Label = "user:" / >
    < mx:ComboBox prompt = "Select" selectedItem = "User2" >
    < mx:dataProvider >
    User1 < mx:String > < / mx:String >
    User2 < mx:String > < / mx:String >
    < mx:String > user3 < / mx:String >
    < / mx:dataProvider >
    < / mx:ComboBox >
    < / mx:HBox >
    < / mx:Application >

    Please let me know if this is possible?

    Thank you

    You must pass a String OBJECT as a selectedItem.

    following code works:

    http://www.Adobe.com/2006/mxml '.

    "" layout = "absolute" xmlns:local = "*" >

    User1

    User2

    Util_3

  • ComboBox with multiple columns

    Is it possible to make a ComboBox with two columns in the drop-down list box?

    Thank you

    Use the dropdownwidth property

  • Fill Combobox with nested XML

    Hello!
    How can I fill a ComboBox with an XML retrieved via a HTTPService?

    My XML looks like

    <? XML version = "1.0" encoding = "iso-8859-1? >
    < xml >
    < node label = value '1' = 'a' / >
    < node label = value "2" = "b" >
    < node label = "21" value = "ba" / >
    < node label = '22' value = 'bb' / >
    < node label = "23" value = "bc" / >
    < / node >
    < node label = '3' value = 'c' / >
    < node label = "4" value = "d" / >
    < node label = '5' value = 'e' / >
    < / xml >

    The output you want in the drop-down list would be

    one
    b
    -ba
    -bb
    Colombia-British
    c
    d
    e

    < mx:ComboBox id = "selectedLevel" dataProvider = labelField 'structure of {}"="label"/ >

    'structure' is an XMLListcollection, looks like my Resulthandler

    structure = new XMLListCollection (event.result.node);


    Can someone give me a hint what is missing?

    Thank you.

  • Fill a ComboBox with actionscript

    I'm currently learning Flash 8 Pro by working my way through a book "Teach Yourself Flash 8' and met an teaching example that does not work." The (very basic) THAT the code needs to fill three lines of a ComboBox (with the instance name "MaZoneDeListeDéroulante"). I rechecked the syntax against that in the tutorial and it fits precisely. However, test results the film in errors such as:

    * Error * scene = scene 1, layer = Layer 1, frame = 1:Line 3: there is no method with the name "removeAll.
    and
    * Error * scene = scene 1, layer = Layer 1, frame = 1:Line 4: there is no method with the name "addItem".

    Can someone help a total Flash beginner who is unsure whether the error is in the tutorial or in its own implementation of it? Or even if there is something wrong with my installation of Flash? I'm learning this step tiny stuff at a time and I'm not convinced to go ahead until I have this problem to be resolved. Shaky foundations and all that.

    Thanks in advance.

    Here's the code AS I use:

    It is resolved. Turns out that I needed to delete the ASO files. I would have never known about this on my own, so thanks a lot go to the author, Phillip Kerman for her help.
    In any case, it is done and dusted.

  • Fill ComboBox with XML data

    I would like to fill a ComboBox with data in a simple xml file like this. It's probably quite newbie question, but I couldn't find the answer to the search in this forum and the documentation up to date.


    < root >
    option 1 < item > < / item >
    option2 < item > < / item >
    Option3 < item > < / item >
    < / root >


    I would be very grateful if someone tell me how the ComboBox control to retrieve data from XML file. Thank you!

    I found a way to do it. Here is the code I use to populate a ComboBox control with dynamically loaded XML data (the XML content is in the first post).
    I'm sorry that I have opened a topic for this fundamental question. In any case I hope that the thread is useful for someone. If you think that there is something wrong with the code below, please post a reply.



    http://www.Adobe.com/2006/mxml"creationComplete ="parseXML (); » >


    public var myXML:XML
    public var myLoader:URLLoader

    function parseXML (): void {}
    myXML = new XML();
    var XML_URL:String = 'content.xml ';
    var myXMLURL:URLRequest = new URLRequest (XML_URL);
    myLoader = new URLLoader (myXMLURL);
    myLoader.addEventListener ("complete", xmlLoaded);
    }

    function xmlLoaded(evtObj:Event):void {}
    myXML = XML (myLoader.data);
    combo.dataProvider = myXML.children ();
    }

    ]]>




  • How can a separator or the second column in the combobox with Labwindows/CVI?

    How can I make custom editable as attached file (Example.jpg) using the ICB library?

    The ComboBox to the figure of capture via MS tool.

    I am a novice in programming as well as the CVI. Please explain in detail if anyone knows.

    You can do this, but it will shows. You can add columns in the control ring menu, so you'll have to create your own popup with a tree control that replaces the menu ring. I have attached a sample program as proof of concept and you get started.

    Hope this helps,

    -jared

  • ListItem customized with Checkbox problem

    Hi I want to create a customListItem with a checkbox. I was able to do, but as soon as I select a checkbox other check boxes were also checked.

    This is my code

            ListView {
                id: lv_cities
                objectName: "lv_cities"
                listItemComponents: [
    
                    ListItemComponent {
                        type: "header"
                        Header {
                            visible: false
                        }
                    },
                    ListItemComponent {
    
                        type: "item"
                        Container {
    
                            background: Color.White
                            Container {
    
                            layout: StackLayout {
                                orientation:LayoutOrientation.LeftToRight
                            }
                            horizontalAlignment: HorizontalAlignment.Fill
    
                            background: Color.White
                            CheckBox {
                                id: member
                                objectName: "member"
                                checked: false
                                onCheckedChanged: {
                                    console.log(ListItemData.name);
                                }
                            } 
    
                              Label {
                                  verticalAlignment: VerticalAlignment.Center
                                  text: ListItemData.name
    
                              }  
    
                        }
    
                            Divider {
    
                            }
                        }
    
                    }
    
                ]
    
                onTriggered: {
    
            }
            }
    

    so if I click on a checkbox it gives me the name of a city, but I do not understand why the other lines are also verified.

    anyone has a similar experience and can help me?

    concerning

    Hello
    ListView is the reuse of ListItemComponents it is during scrolling.
    For this reason, box remains in a State that is activated when reused.

    Checkbox State can be stored in the data model. Bind the checkbox checked property to scope a datamodel, in this way, it will be reset to reuse.

    DataModel can be ArrayDataModel, GroupDataModel or any other type of model.

    In general, the idea is that all the information given and the State is stored in the model, ListItemComponents display only the data to the appropriate lines.

Maybe you are looking for

  • I can't move the firefox window, or use the reduce/close/maximize buttons. I have no addons

    I'm on windows 8.1, and firefox worked fine yesterday. Today I can't move the window, reduce, enlarge and close without end of tasks, tried refreshing, reinstall. Still nothing. The only addon I ever is adblock and when retired that didn't fix it eit

  • Keyboard is fine, but it won't let me type?

    When I turned on my laptop, entered my password and failed in my laptop no problem. I typed all the keys - all typed. Even all keys have their lights. But suddenly, some keys don't work well. I don't know I don't turn something liquid on the keyboard

  • Location information of photos

    I went to a concert at Wembley Stadium.  Some of these photos I took were correctly located in London, but some have been civic in Coventry (different Stadium - next date of the tour!). Can I change the location information or delete it in the photos

  • Wireless will not allow on the laptop HP 2000

    Help! I have a laptop HP 2000 and all of a sudden the wireless function does not work. No matter what I do the rest orange button. I don't have Wireless Assistant installed on this computer. I tried to download it from another computer and install to

  • Vista will not start on Aspire 5515

    It gets to the loading screen, but there is not windows - only the loading bar logo... and he was. Then when I tried to install another OS (XP pro, the only startup disk that I have), as soon as he launched into "Starting Windows."... "I armored blue