JTable cell value passed to textarea on single click - java

On my form I have a jtable and a textarea. My table only has 2 columns - ID and Comment
Is it possible that when a user clicks on a cell in the comment column. The cell value will appear in the textarea in edit mode?
I did set the cell editor to singleclick
selectTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumn col = selectTable.getColumnModel().getColumn(1);
DefaultCellEditor singleclick = new DefaultCellEditor(new JTextField());
singleclick.setClickCountToStart(1);
col.setCellEditor(singleclick);
I have a method outputSelection() that gets called from a edit button. The method gets the value from the selected cell and puts the value in the textarea for edit.
Can the click activate the method so the user does not have to click a edit button?

You could attach a mouse listener to the table and monitor the mouse clics from there, getting the selected column/row & thus the value
You could supply your own cell editor that updates the text area when the editors value is set
You could extend te jtable & when cell editing is started, update the text area

Yes, this is a process I learned to use after having duplicate code throughout my swing application. I started making standalone methods that did the work I wanted, and then I call those methods from the action events from the button or mouse click. That way they all execute the same code.
Even if you have a tab or enter key command, you can also have it execute your same method as the others for more consistent code.
If your button performs specific code with cell values, just extract all of that code out into a method that takes the cell value as input. Then you can call that same method from any event and pass in the input data you want to display in the text area.

Related

Jasper Report with Buttun Jtable parameter

My Table
strong text
How to Great view a Report Invoice from parameter Jbutton Table (After Clik Button Jtable can Preview Database Click) ? please help me !
Creating a cooperative Invoice with invoice details on Frame DETAIL
TABLE CONTRIBUTION.
When the process is going well, sy obstacles pd part JTable Button
To Display Description The contents of invoices that have been made
previously (such as images SC Upload)
Main problem is, how can I show ISI INVOICE through parameter JTable
Button in a Column "OPTION" and when in Click "View details" will
show Jasper Invoice Report in accordance with the selected table ??
ths Before it !
My problem is when I click the button in the table (JTable button), I do not have any reaction
You need to implement a custom editor for that column.
Check out Table Button Column. It shows how to use a button as custom renderer/editor for text in a column. Then you just provide the Action you want to be invoked when the button is clicked.
The column must be editable for the Action to be invoked.

JTable setRowSelectionInterval has no effect for JButton

Using a JTable, my Table Model setValueAt() method moves the selection to the next row in certain cases, using setRowSelectionInterval() and setColumnSelectionInterval(). When it's called from the (default) cell editor (by user typing in the cell and hitting tab), the code works: the desired next cell is selected (the first one on the next row).
However, if the user uses Return rather than Tab to commit the edit, the selection doesn't happen; instead the cell below is selected. That's fine with me.
I also have a JButton to clear a row. The button's action function calls the model's setValueAt() function for the desired cells. Unfortunately, the setRowSelectionInterval() and setColumnSelectionInterval() methods have no apparent effect; instead, no cells are selected.
I've tried table.requestFocusInWindow() and table.getParent().requestFocusInWindow(), as well as table.changeSelection(row, 0, false, false), all to no apparent effect.
Is there anything basic I'm missing here, before I go to the trouble of building the SSCCE?
In case it matters, here's the container hierarchy:
parent JPanel
button rows JPanel
button row 1 JPanel
button row 2 JPanel
table JScrollpane
JTable
The button in question is in button row 1.
Thanks!
Maybe you can use the Table Cell Listener to listen for edits to the table. It listens for actual changes done by the JTable editor.
Then in the supplied Action you can select the appropriate row. You may need to wrap the Action code in a SwingUtilities.invokeLater(...) to make sure the code executes after the table is completely finished editing.

Edit JTable in Netbeans Builder

I designed a JTable with Netbeans Builder and I created 5 columns, the 5th one is Boolean so I want to know how to highlight whole the row when the user selected.
See Table Row Rendering for an easy way to color an entire row based on a value in the row.
The problem now is that only the cell is automatically repainted when you click on the checkbox so you will also need to add a TableModelListener to the TableModel so you can invoke a repaint() on the table row whenever the state of the checkbox is changed.

How to enable using arrows keys to move row selection in JTable?

I noticed that I can you arrows to move row selection of my JTable object only when I press tab key. Is it possible to use arrows after row selection by mouse-click (instead of using TAB)?
In order for the arrow keys to change row selection, the JTable must have focus. Pressing the tab key changes focus to the next (or first) "focussable" Component on the page which is likely a SubComponent in the JTable.
To get it to focus automatically when it becomes visible, add a ComponentListener with the an componentShown(...) method implemented to call the JTable's requestFocusInWindow() method.
Is it possible to use arrows after row selection by mouse-click (instead of using TAB)
Yes; if you click the mouse on a row, that should also focus the row, allowing you to use the arrow keys as well.
Updated: corrected method used to get input focus, with thanks to camickr (see comments)

linking jcombobox values with jtextfield values

I've created an application in netbeans IDE 6.9 where I need to set values for each value in the jcombobox. In my pane I've a combobox and below that are the textfields for entering values for each value in the combobox. Can anyone suggest that how do I link the combobox with textfield. I mean there are different values for each value in the combobox. I want that user selects a value in the combobox then its corresponding value should be displayed(if it has already been entered) otherwise a blank space should be shown. I want that all the values for each combobox values should be set in one go(the user should not press the ok button).
-Thanks in advance
Wouldn't you want to use an ActionListener? Then when an ActionEvent happens for the combo box you could fill the text field with the values from the currently selected item? And if blank then allow them to add to the text field and have an ActionListener on that where if the value is not in the list that is in the combo box to add it to the list in the combo box?
I can only guess from the question that each item in your combo box is an object and you want to edit multiple fields of the selected item.
You could use a bunch of individual text fields, one for each "value" in the selected "value in the combobox".
A better UI would be a property pane to list and edit the fields. The commercial PropertyGrid in JIDE Grids can actually combine the combobox and property pane in one place.
You can commit each field value after it is entered, or commit all when the editor loses focus (for example when you select another item in the combo).
jComboBox1.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent ie)
{
String str = (String)jComboBox1.getSelectedItem();
jTextField1.setText(str);
}
});

Categories