Ive got a weird issue, hoping someone can help. Ive got a bunch of different tables, added to panels, added to a common scrollpane. When a user clicks on a cell, it highlights it to show the cell selection, just the standard highlight, this is fine. I set:
tables[nr].setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
When you click on a different table though the original table keeps its selection highlight. Only if you click on a different cell within the same table does the selection change.
Is there any way to only have 1 cell selected at a time for this setup I have here? So only 1 cell selected throughout all the applicable tables
Thanks
In case someone is looking for a quick solution to the problem, here is the code for deselecting all the selected rows and columns of the table, once the table looses focus.
jtable.addFocusListener(new java.awt.event.FocusAdapter() {
#Override
public void focusLost(java.awt.event.FocusEvent evt) {
clearSelection();
}
});
Simply add this focus listener to each of your tables and their selected rows and columns will be deselected, once you select the records in a different table.
Related
I have created JTable with TableModel in which I make column Product Id as editable. This jtable is shown when i click one cashMemoBtn and if i type product id in first row and hit enter key then it is adding new empty row to jtable. But my problem is when new Empty row is added then Product Id Cell should have blicking cursor like we see in any editor OR in textfield.
I have attached my expected output screenshot here
In image you can see vertical bar which is indicating current focus but i want it should be automatic for all new rows when i add new rows.
I tried with
jTable.setEditingColumn(1);
jTable.setEditingRow(0);
But is not working as per my requirement. Please help.
Thanks in advance.
After you add the empty row of data to the table you then need to start editing on the desired cell.
The basic code would be:
if (table.editCellAt(row, 1))
{
Component editor = table.getEditorComponent();
editor.requestFocusInWindow();
}
I have a very basic problem with jtable. I have a jtable that has multiple columns with one of column having a button. When i click on that button a panel drops, and asks to select an option from given options. When i select that option, value replaces in one of the column.
Now, i want when i select multiple rows, and do the same thing as above, it should replace that column in all the selected rows.
Problem: Currently, my table is losing selection when i am clicking the button in one of the column in jtable after multiple row selection.
I searched google and stackoverflow a lot, but could not find anything meaningful. Anyhelp or sample code is appreciated.
Thanks
If I understood your problem correctly then the solution is fairly simple.
First of all the issue probably occurs because once you click on the button java sets a new focus on the button and therefore clearing the focus on the other rows. That won´t be a problem in a single selection because you still click into the selected row, however doing that with multiple rows in one go won´t work that way.
To solve this you need to save your previous selections in something like an ArrayList and after the whole option thing you can apply the changes to every element in the ArrayList and reload the table.
A cleaner and more intuitive approach though would be to place the button outside of the JTable.
I have a JTable in which one column is a checkbox. I want to let the user edit the checkbox by mouse drag: if they clicked one checkbox and drag mouse into other checkbox, they will get the same result with the first checkbox clicked.
One approach is to specify ListSelectionModel.MULTIPLE_INTERVAL_SELECTION for the table's selection model, as shown here. Click and drag to select contiguous rows, or add the shift, control or command modifiers to select disparate rows. In a suitable Action, update the TableModel to reflect the selection, as shown here. The JTable will update itself in response.
I have a JavaFX TableView with some columns and some rows. Each column has a custom TableCell to be edited, for example: some columns use text fields, some others use check boxes, choice boxes and so on.
What I want is to edit several cells (simultaneously) in the same column by doing the following:
Select some rows in the TableView.
Click on a cell using the right mouse button.
A context menu is shown with the option "Edit All"; choose it.
Somehow I edit one of those cells and every cell in the same column whose row is selected commits the same value.
What I want to know is whether it is possible for every cell to “commitEdit” the same value. I cannot find the way of doing it.
Thanks in advance.
I want to create a table (that will finally exist in a new eclipse view). This table has a few text columns, and a column that has a different behavior based on the other columns. It can either be a field to enter text, or to popup a dialog for users to select data from (and it has to be a popup or a dynamically created combo). Anyway, I know which of the two I need for each row in the column.
My table is built using TableViewer and a few TableViewerColumn's in it. I later fill them with String data in TableItem's up to 4 columns. The fifth is the one I have this special behavior.
I tried experimenting with TableEditor, but failed:
When I used one for each TableItem it somehow got misaligned with the table rows and columns
When I use one for the entire table, I fail to set a Text entry on specific rows
What I need help with is figuring out exactly how to achieve this:
A Table that has 4 String columns, where the data is constant (cannot be changed by the user)
A fifth column where the cell contents is either a Text for the user to enter, or a (preferably transparent) Button that has a popup as action, or a Combo that I dynamically fill with data upon table creation
Any idea would be highly appreciated.
OK, got this figured out. The example here helped a lot:
http://www.java2s.com/Tutorial/Java/0280__SWT/TableCellEditorComboTextandButton.htm
Oren