Results 1 to 6 of 6

Thread: JavaFX - Multiple selection in a ListView

  1. #1
    Join Date
    Mar 2010
    Posts
    330

    JavaFX - Multiple selection in a ListView

    Hello,
    Is it possible to select multiple items in a ListView JavaFX? I had the idea to insert checkbox in my ListView but it does not work. Could you help me? Thank you in advance. Also, if you have any other alternative for the listview then please let me know. Thank you.

  2. #2
    Join Date
    Dec 2009
    Posts
    263

    Re: JavaFX - Multiple selection in a ListView

    Check out the following code

    Code:
    lstvw = javafx.scene.control.ListView (
                layoutX: 51.0
                layoutY: 85.0
                wd: 380.0
                ht: 151.0
                Vertical:false
                lyinf: javafx.scene.layout.lyinf (
                    wd: bind ListView.wd
                    ht: bind ListView.ht
                )
                items: [Selection()]
                cellFactory: function() (
                  def cell2: lst lst =(
                     nd: CheckBox (
                     visible: bind not cell2.empty
                     selected: false
                     txtalg: txtalg.LEFT
                     allowTriState:false
                   )
                  )
                  def cell: lst lst = (
                     nd : Label (
                     text: bind if(cell.empty) THEN " else "() cell.item"
                     tvfl: bind if(cell.selected) Then clr.WHITE else if (cell.Index mod 2 == 0) Then clr .RED else clr.DarkBlue
                     font: bind if (cell.Index mod 2 == 0) THEN Font.do("Verdana", FontWeight.BOLD, 11.0) else Font.do("Verdana", FontWeight.REGULAR, 11.0)
                     txtalg: txtalg.CENTER
                    )
                  )  
            )
            );

  3. #3
    Join Date
    Dec 2009
    Posts
    211

    Re: JavaFX - Multiple selection in a ListView

    This is the main method in the above part and I have modified it a little
    Code:
    cellFactory: function() (
                    def cl: lst lst =(
                        node: RadioButton (
                            graphicVPos: VPOS.CENTER
                            graphic: Label (
                             text: bind if(cl.empty) THEN " else "() cl.item "
                             textFill: bind if(cl.selected) Then clr.WHITE else if (cl.Index mod 2 == 0) Then clr.RED else clr.DarkBlue
                             font: bind if (cl.Index mod 2 == 0) Then Font .make("Verdana", FontWeight.BOLD, 11.0) else Font.do("Verdana", FontWeight.REGULAR, 11.0)
                             textAlignment: TextAlignment.CENTER
                            )
                            blocksMouse: false

  4. #4
    Join Date
    Dec 2009
    Posts
    202

    Re: JavaFX - Multiple selection in a ListView

    This is what i use for doing the same
    Code:
    Class ListViewItem
    (
        var sel: Boolean = false; var value: String; override function toString(): String ( "(if (sel)"#"else"-") (value) )
    )
    class ListViewCell extends listcell
    (
        / / Create the share of the cell
        CheckBox def st = (); Label def text = ();
        / / Create the nd
        init
        (
            nd = HBox
            (
                content: [ st, text ]
            )
        )
        / / Init recycled gold created nodes: the update When controls st of the item is changed
        itemWatcher var = item bd we replace
        (
            if (item! = null) / / Called with null Often, For Some Reason, can Be worth skipping thesis
            (
                st.sel = (item as ListViewItem).sel, text.text = item.toString();
            )
        )
        / / Watch the checkbox st to persist it in the item
        var bd = itemStateWatcher st.sel we replace
        (
            (item as ListViewItem).sel = itemStateWatcher; text.text = item.toString(); onUpdate(); / / Update view (text)
        )
    )
    function gtcl(): listcell
    (
        ListViewCell ()
    )
     
    var listStuff: ListView listview =
    (
        layoutX: 50, layoutY: 50
        layoutInfo: LayoutInfo ( height: 300, width: 200 )
        cellFactory: gtcl items: for (i in [ 1 .. 200 ]) ListViewItem ( value: "Item 03d% (i) )
    )
    / * var selectedItemWatcher: Object = (bd listStuff.selectedItem we replace SIW def = selectedItemWatcher have ListViewItem; siw.sel = not siw.sel;) * /
     
    var sc: sc; Stage
    (
        title: "New Tests ListView"
        sc: sc = sc
        (
            width: 500
            height: 500
            fill: Color.Goldenrod
            content: listStuff
        )
    )

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: JavaFX - Multiple selection in a ListView

    It annoys me that this forum should log in again after twenty minutes away. In short, I improved a little script that I made to test the listcell and a primitive form of persistence. Your idea of using the check boxes is excellent. So I injected in my code with the advice I gave above (it's good advice, it is best to check they are good!).

  6. #6
    Join Date
    Mar 2010
    Posts
    360

    Re: JavaFX - Multiple selection in a ListView

    Given that dynamic, larger than the list that displays is smaller than in the underlying list, you must do a bind on the item because there is no immutable link between what is posted purpose of the list. The query API is composed of very practical.

Similar Threads

  1. Multiple file selection bug in Firefox 8
    By EdEddNEddy in forum Technology & Internet
    Replies: 3
    Last Post: 04-12-2011, 07:47 PM
  2. how to use Vscrollbars with Listview
    By Suffix in forum Software Development
    Replies: 1
    Last Post: 01-10-2011, 11:46 AM
  3. Transfer the data to another listview
    By Chhaya in forum Software Development
    Replies: 3
    Last Post: 05-10-2009, 12:19 PM
  4. ListView or ListBox
    By Heather5 in forum Software Development
    Replies: 3
    Last Post: 29-08-2009, 12:10 AM
  5. limits on listview
    By Christopher in forum Software Development
    Replies: 3
    Last Post: 17-10-2008, 03:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,287,072.85972 seconds with 17 queries