I am trying to get the selection from a TableView in JavaFX 2.0. I have stored 5 Persons (5 rows) in the TableView. The code to get the selection model is:
TableView<Person> tableView =
myStage.getTableView();
ObservableList<Person> selection =
tableView.getSelectionModel().getSelectedItems();
System.out.println(selection.size());
Now when I select multiple rows and then execute the method including the above code, the following prints the selection * 2 and sometimes the selection * 3. For example: I select all 5 rows and it prints out a size of 10 and sometimes 15!
What am I doing wrong here?
There is a bug with TableView returning duplicated items for selection made by shift-click.
As a workaround until fix you can try filter duplicated items by:
Set<Person> selection = new HashSet<Person>(tableView.getSelectionModel().getSelectedItems());
Related
I have two forms for EmployeeDetail and DriverDetail for entering data.
Form 1 has 8 columns viz-Date,Name,Accno,ifsc,Amt,Mode,Comp,Salarymonth
Form 2 has 12 columns where 1-7 is same except SalaryMonth column plus 4 more AccHolder,Bank,Remark,Purpose in Form2 i.e DriverDetail
I have created a JFrame class for searching and retrieving data which will be shown below in the JTable.
My Coding is finished till designing of 2 forms now retrieving data from DB to JTable is pending .
While coding for JTable the below question arose ?
My Question is:
Do I have to design two JTable for retrieving from each form as there is no. of column mismatch?
Or Is it possible to use same JTable for both different forms ?
When i select EmpDetail then JTable with 8 column must appear and when i select driverDetail then JTable with 12 column must appear
Please suggest what can be done.
I created a GUI which contains a JComboBox and a JTable. The JTable is filled with data from an Access Database. The JComboBox is used to filter the JTable.
When I select an item from the JComboBox the JTable shows the correct data. But if I first select a row from the JTable and select another item from the JComboBox I get the following error:
java.lang.ArrayIndexOutOfBoundsException: -1
What’s the problem here?
Any time you throw an ArrayIndexOutOfBoundsException the issue lies in that you are trying to select data that lies outside the working area for the data set (Array in this example. Arrays use 0 based indexing). First I would ensure the data in your JTable is correct, then I would look at how the relationship between the JTable and JComboBox is defined.
Would be easier if you also included some of your code so we could actually see the error in your design. Best of luck!
I have in my program a customized JFileChooser. Calling the JFileChooser a detail view is shown where files are sorted by descending date.
Until Java 8 the sorting of files ran without problems. Since 2 weeks, we have Java 9 because we need some new functionalities. Under Java 9 the JFileChooser sort does not run anymore.
The Code is the follwing:
public class JFileChooserCustom extends JFileChooser {
....
....
JTable fileChoosertable = SwingUtils.getDescendantsOfType(JTable.class, this).get(0);
TableColumn column3 = fileChoosertable.getColumnModel().getColumn(3);
column3.setPreferredWidth(120);
fileChoosertable.getRowSorter().toggleSortOrder(3);
fileChoosertable.getRowSorter().toggleSortOrder(3);
....
I called toggledSortOrder twice that the files wille be sorted by descending Dates.
Since Java 9 toggleSortOrder on the date column has no effect. I tried to implement an own rowsorter but it resulted in a many side effects. So, after sorting, the wrong files were selected. A implemented a new mouse listener which converted the selected rows numbers into the row numbers of the table model, but new side effects resulted.
Is there anaybody who knows a solution?
I've got a primefaces datatable with some data generated, with multiple selection and pagination and i have to count all the selected rows on each page and i done this but the problem is that i have to count also the number of subpages with selected items on it. So if i check 3 items on page number 1 and 3 items on page number 3 i want an output like: selected: 6 subpages: 2. Is there an easy way to count subpages ? For counting rows i just use a lenght of selected items table. How can i do this ?
You could use a listener in the bean to get current page onselection and kept a tally.
EX.
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot()
.findComponent("someOformID:someTableId");
dataTable.getPage()
I'm using Eclipse Indigo SR1 with JDK 1.7, on Windows 7 Pro.
I've written a desktop app, Swing based.
My app includes a JTable; it shows many records of type T, one row per record.
The table model points to Vector vect, named vect, containing all data to be shown in the JTable.
The app includes a combo, named sele, showing three values: 0, 1, 2.
When sele = 0, every record of vect has to be visible in the JTable.
When sele = 1, the JTable has to show only vect records having odd row index and all records with even row index mustn't be visible. Viceversa, when sele = 2.
So, here's my question: how can I make a row not visible in the JTable ?
I can't use the table model, because it points to vect that contains "all" data.
I tried a table cell renderer, but it seems that you can set the color of a cell, but you can't set it not visible or modify its size.
I've tried another way: if r is the row index, and I want that row to be not visible, I write table.setRowHeight(r,0), but this instruction throws an exception, the height can't be set to zero.
I could solve the problem by splitting the data, dividing vect in two, but I don't like that.
Does anybody have an idea ?
thanx in advance,
William
PS: someone told me to create a filtering TableModel that wraps the existing TableModel. The filtering model would be sensitive to the filtering criteria and fire the appropriate methods (TableDataChanged) when the filter was changed. The getRowCount method would return the filtered count. The getValueAt method would map the filtered row to the actual row in the underlying TableModel.
Mah, perhaps it's a good idea, but frankly I'm not able to understand it...
Use a TableRowSorter - which is:
An implementation of RowSorter that provides sorting and filtering using a TableModel. ..
See How to Use Tables & especially Sorting and Filtering for more info.