• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple Selection of ListItems using JavaFX

 
Mathew Kuruvilla
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • 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: 143
  • Mark post as helpful
  • send pies
  • 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: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Can somebody tell me how to make my above solution scrollable?
 
Mathew Kuruvilla
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • 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 . . .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic