wood burning stoves 2.0*
The moose likes JavaFX and the fly likes Multiple Selection of ListItems using JavaFX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Multiple Selection of ListItems using JavaFX" Watch "Multiple Selection of ListItems using JavaFX" New topic
Author

Multiple Selection of ListItems using JavaFX

Mathew Kuruvilla
Ranch Hand

Joined: Nov 27, 2001
Posts: 135
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

Joined: Nov 27, 2001
Posts: 135
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

Joined: Nov 27, 2001
Posts: 135


Can somebody tell me how to make my above solution scrollable?
Mathew Kuruvilla
Ranch Hand

Joined: Nov 27, 2001
Posts: 135


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 . . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Selection of ListItems using JavaFX
 
Similar Threads
JavaFX Future
JavaFX Testing Frameworks available?
Embedding Jetty inside a JavaFX app
storing files at ftp server
JavaFX on symbian possible ?