How can I select multiple cells in tableview with javafx only with the mouse?
I have an application with a tableview in javafx and I want to select more than one cell only with the mouse (something like the selection that exists in excel). I tried with setOnMouseDragged but I cant'n do something because the selection only returns the cell from which the selection started. Can someone help me?
For events of the mouse to be propagated to other than the node in which nodes the drag started, you must activate a 'full-drag-release press gesture' by calling startFullDrag (...) on the original node. (For more details, see the Javadocs MouseEvent and MouseDragEvent .) You can register for MouseDragEvents on cells of the table in order to receive and process these events.
Here's a simple example: the user interface is not supposed to be perfect, but it will give you the idea.
import java.util.Arrays; import javafx.application.Application; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.input.MouseDragEvent; import javafx.scene.input.MouseEvent; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.stage.Stage; import javafx.util.Callback; public class DragSelectionTable extends Application { private TableViewtable = new TableView (); private final ObservableList data = FXCollections.observableArrayList( new Person("Jacob", "Smith", "[email protected]"), new Person("Isabella", "Johnson", "[email protected]"), new Person("Ethan", "Williams", "[email protected]"), new Person("Emma", "Jones", "[email protected]"), new Person("Michael", "Brown", "[email protected]") ); public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Table View Sample"); stage.setWidth(450); stage.setHeight(500); final Label label = new Label("Address Book"); label.setFont(new Font("Arial", 20)); table.setEditable(true); TableColumn firstNameCol = new TableColumn<>("First Name"); firstNameCol.setMinWidth(100); firstNameCol.setCellValueFactory( new PropertyValueFactory ("firstName")); TableColumn lastNameCol = new TableColumn<>("Last Name"); lastNameCol.setMinWidth(100); lastNameCol.setCellValueFactory( new PropertyValueFactory ("lastName")); TableColumn emailCol = new TableColumn<>("Email"); emailCol.setMinWidth(200); emailCol.setCellValueFactory( new PropertyValueFactory ("email")); final Callback , TableCell > cellFactory = new DragSelectionCellFactory(); firstNameCol.setCellFactory(cellFactory); lastNameCol.setCellFactory(cellFactory); emailCol.setCellFactory(cellFactory); table.setItems(data); table.getColumns().addAll(Arrays.asList(firstNameCol, lastNameCol, emailCol)); table.getSelectionModel().setCellSelectionEnabled(true); table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); final VBox vbox = new VBox(); vbox.setSpacing(5); vbox.setPadding(new Insets(10, 0, 0, 10)); vbox.getChildren().addAll(label, table); ((Group) scene.getRoot()).getChildren().addAll(vbox); stage.setScene(scene); stage.show(); } public static class DragSelectionCell extends TableCell { public DragSelectionCell() { setOnDragDetected(new EventHandler () { @Override public void handle(MouseEvent event) { startFullDrag(); getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn()); } }); setOnMouseDragEntered(new EventHandler () { @Override public void handle(MouseDragEvent event) { getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn()); } }); } @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (empty) { setText(null); } else { setText(item); } } } public static class DragSelectionCellFactory implements Callback , TableCell > { @Override public TableCell call(final TableColumn col) { return new DragSelectionCell(); } } public static class Person { private final SimpleStringProperty firstName; private final SimpleStringProperty lastName; private final SimpleStringProperty email; private Person(String fName, String lName, String email) { this.firstName = new SimpleStringProperty(fName); this.lastName = new SimpleStringProperty(lName); this.email = new SimpleStringProperty(email); } public String getFirstName() { return firstName.get(); } public void setFirstName(String fName) { firstName.set(fName); } public String getLastName() { return lastName.get(); } public void setLastName(String fName) { lastName.set(fName); } public String getEmail() { return email.get(); } public void setEmail(String fName) { email.set(fName); } } }
Tags: Java
Similar Questions
-
How can I select multiple cells in dreamweaver cc?
Can't get cursor seems to break and merge cells in a table. Continues to move entire cell.
Thank you
Winifred
Sounds strange, ideas? And thank you once again.
-
How can I select multiple messages at the same time for archiving
I want to archive multiple messages in a folder from archive. How can I select multiple messages at once?
To select a block of eg: 10 emails.
- Click on the first email
- Hold down the SHIFT key and click the last email.
- This will highlight all in the interval
To hightlight all the emails in a folder.
- Click on the first email to focus.
- Press on and hold down the 'Ctrl' key and press 'A '.
- This will highlight all emails.
To select several emails:
- Press and hold down the 'Ctrl' key and then use the mouse to select multiple e-mails
- they will appear as "conversations in the messages pane.
- Click on archives.
Info on setting up your archive' Options ': '.
-
How can I select multiple files without copying them accidentally?
Select several files control
On this Microsoft Web site, you will find that one answer and nothing is sent. I want to say is that you can select multiple files/folders-press control button select yourvnormal.
Sometimes my stuff gets copied/recopied
How you can select multiple files without looking at Microsoft re copy?
You can activate the checkboxes in the folder options point.
http://Windows.Microsoft.com/en-us/Windows7/change-folder-options -
How can I create a simple virtual machine with the CD in a newWorkflow
I created a new workflow with simple virtual machine and added a cdrom workflow but an error is shown.
How can I reuse of so that the new created VM add a new cdrom in a workflow
Help me please
First of all, you only need a single attribute of type VC:VirtualMachine, not two as in the screenshot. You don't need to specify its value; When the first workflow completes, its output should be attributed to this attribute, and then the assigned value must be passed as input to the second workflow.
To check/edit links, open the first workflow to change, go to the 'Visual links' tab and make sure the workflow output is line connected to the attribute. Do the same for the second workflow, and then make sure that the attribute is connected to the line to the corresponding input parameter.
Take a look at the workflow attached if you don't know how the maps should look like.
-
How can I add an effect of light with the code box and the javascript to a Web of Muse site?
I have a finished site that I built in Muse. On one of the pages, I would like to add a light box effect, but none of the widgets that Muse. I wonder if someone can tell me how to go and add code and java script. I have the code and everything, I just need to figure out how to add in the code before I publish it online. Can someone help me?
You insert the HTML Manual.
Mylenium
-
I can't select more than one object with the SHIFT key, selected in the last Muse app
Someone who uses the worm. last Muse CC 2014 with Mac OS 10.10.2 and had a problem of selection of several objects by using the Shift key and hold the method has a work around. It's frustrating to try to select several objects and this simple technique does not. This same shift-SELECT approach works fine on the same calculation with other products Adobe such as PS, AI, Id etc.
I tried your suggestion to select multiple layers but no joy and no floating above the ones I had to choose. I discuss with a representative of Adobe this morning and discovered that it is possible to select more than one by dragging on the elements with the selection arrow. This forces me to block these unwanted layers selected in this shotgun approach first. It's my best work around so far. Shift-click works in the old Muse vs7.4.30 app on the same computer. I enjoyed your suggestion and hope there is a fix for the simple approach shift-click.
-
How can I make a text transparent marking with the courier in InDesign CC?
How can I mark text with the courier and see things that are behind it (next layer...)
Of course, it works in Version CS5.5.
I havn't found a preference for this problem.
THX 4 help
drx_ander wrote:
I'm going to think it was a missunderstanding. So I did the screenshots of the problem.
No misunderstanding. Text highlighing was transferred to the operating system. There are no settings in the ID that will change the new behavior.
-
If I have a plan of photography, can I select a single App plan with the same account?
Then I can have the same both times?
I have need for all applications, only Photoshop and Illustrator.
Hi Barpaff,
Yes, you can add illustrator with the same account. So, you are going to have two applications. ((1) creative cloud photography Plan and unique Cloud 2) Creative app Illustrator.
You can add as many as the only application on the same account, but the application must be different.
Let us know if you need more information.
Thank you
Florianne Jindal -
Windows XP Pro, SP3. Firefox 3.6.3. Since the update to this version a few weeks ago, that I can no longer do a right-click of the mouse and check the properties of an active url link on Web pages. I've always had the option before. I want this feature back!
This add-on restores the functionality of properties: https://addons.mozilla.org/en-US/firefox/addon/14228/
-
How can I select multiple photos to send a file by email?
SELECTION AND SENDING SEVERAL PHOTOS IN AN EMAIL? HOW DO U DO?
The following items may be worth a visit:
Windows Vista - tips for emailing photos
http://Windows.Microsoft.com/en-us/Windows-Vista/tips-for-e-mailing-photosWhen you use the "slide show" option... photos
are uploaded to the Windows Live servers.Add Photos to e-mail Messages
http://explore.live.com/mail/add-photos-to-e-mail-messagesMessages of E-mail photo
http://explore.live.com/mail/about-photo-e-mail-messagesWhat is Windows Live SkyDrive?
http://windowslivehelp.com/solution.aspx?SolutionID=679c5c15-39a0-4899-a9ae-160eeb32d963Windows Live Mail - picture Message
Mail: Send a lot of pictures
http://explore.live.com/Windows-Live-Mail-photo-using?OS=otherHow many photos high resolution can I send using a slide show?
http://explore.live.com/Windows-Live-Mail-Photo-email-high-res-resolution-FAQ -
How can I select multiple items in the list of the spark without pressing the command?
Hi all
I need to change the behavioral list to allow multiple selections by clicking on each item
In the list, instead of using the control
30:
Elazar r
This blog explains how: http://flexponential.com/2009/12/13/multiple-selection-in-a-spark-list-without-the-control - key /
-
How can I select multiple slides to be copied?
Hello
I think there's an easy way to do this, but my brain didn't think of it again.
How to select a range of slides to be copied to another presentation in Keynote?
Thank you
Thanks everyone, I just figured this out.
Shift + select
Too easy, a bit embarrassed to be honest.
-
How can I select multiple files in the grid to import view in LR4?
So far, the only way I found out is laboriously click on the box on every image I want to import. It seems we should be able to select a range with one click (for example holding SHIFT and clicking the last image in the range) or by using a menu popup (right click). No dice. What gives?
I think two groups of developers on two different planets designed differeng library vs import views - they are of course different.
I can answer your question because I had the same issue and has spent weeks by clicking on each one individually.
First ignore the checkboxes. Then click on use, ctrl + click, shift + click to select thumbnails (NOT the check boxes, that's why I said to forget for the moment!)
Once you have selected what you want, find one of the selected photos, and then click its box one way or another, each click selects or deslects all 'selected '.
-
How can I stop firefox 29,0 start with the page tutorial every time I open it?
I get 2 tabs opening are the tutorial page and the other is my home page. Very annoying and me are gone through any step hoping this would complement something and had no chance to solve this issue.
Hello, this can happen when firefox is not able to correctly save preferences in the profile folder. Please try this: click the menu button
then click on help
> troubleshooting information > profile folder - 'display the folder '. then a new window will open. in this search on a file named user.js window (it can be used to overwrite your custom settings). where it is present, delete or rename this file and then restart firefox.
For more information and other steps, please also see: How to fix preferences that will not save
Maybe you are looking for
-
Mozilla think I'm under v6 - I am actually running v25. Why?
Your site think that my version of FF is outdated and I use Windows7. I'm not. I am running FF on Mac OS 10.6.8 25.0 v (Netalyrz also I'm bf6 under Windows.Your convenience store also I am bf6 under Windows.) "About Firefox" watch v 25.0
-
Ref FPGA type-def lost connection when moving to another computer
I have a VI that opens an FPGA VI reference and links the reference to the type definition. The VI works fine on a single computer (Win7; LV 2010, module FPGA 10.0.0). However, when I open the same VI on another computer (WinXP, LV 2010, module FPGA
-
I think that my windows installer is damaged I looked for error codes and it is said to run fixit and I did. FixIt says it can't find steps and problems, I also used various suggestions online rInstaller windows install but when I try to rename msli.
-
XPS13 built in microphone not detected.
On a Dell XPS 13 Ultrabook, running Windows 7 ultimate (downgraded from Windows 8). The system is not just see the microphones. On the windows volume control options/recording devices, nothing comes up. Even on Dell Audio / microphone and Skype mic
-
Windows and Nero reports missing atl100.dll 2015
Is there some other way that restore Windows 7 Home Premium to fix programs report a Windows system file are missing. As with XP, you can put the installation disc in and repair. I programs telling me that "atl110.dll" is missing, I checked and it's