• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple Selection of ListItems using JavaFX

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to use JavaFX and be able to select multiple items from a list.
Generally, this is possible with all list like controls in Swing, HTML etc.
It looks like this is not possible with either the Cross Platform ListView control
or even the SwingList component available in JavaFX . . . . .

Or am I missing something here?
 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I did to get a list that can have multiple selection:

import javax.swing.DefaultListModel;
import javafx.ext.swing.SwingComponent;
import javax.swing.JList;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class SwingList extends SwingComponent {
public def vertical : Integer = JList.VERTICAL;
var list: JList;

public var listener: ListSelectionListener on replace {
list.addListSelectionListener(listener);
}

public var orientation: Integer = vertical on replace {
list.setLayoutOrientation(orientation);
}

public var visibleRowCount: Number on replace {
list.setVisibleRowCount(visibleRowCount);
}

public var data: Object[] on replace {
var m: DefaultListModel = new DefaultListModel();
for (val in data)
m.addElement(val);
list.setModel(m);
}

protected override function createJComponent() {
list = new JList();
return list;
}

public function getSelectedValues(): Object[] {
return list.getSelectedValues();
}
}

and yes it has been tested and found working :-)

If anybody can tell me a way of doing it by simply using JavaFX libraries, please do so.
Thanks.
 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Can somebody tell me how to make my above solution scrollable?
 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


And again, I solved it:

var sList: SwingList = SwingList {
data: ["test1", "test2", "test3"]
visibleRowCount: 3
}

var region: SwingScrollPane = SwingScrollPane {
view: sList
scrollable: true
}


The above code has been modified from the source to make it look generic, hence there may be compilation problems . . .
 
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic