How to refresh an existing row of a JTable
Hi all,
I have to refresh the data of an existing row of a JTable after some time in thread. The code snippet is
DefaultTableModel model=new DefaultTableModel(data,columnNames);
table = new JTable(model)
public boolean isCellEditable(int row, int col)
return false;
Now I also add rows to this table within the run() of the thread as
model.addRow(new Object []{sub1,sub6,sub12,sub3,sub18});
My problem is that I want to refresh the data of this added row within the thread.
Any help is highly appreciable. Thanks in advance.
Regards,
Har Krishan
Hmmm. His qhestion does not seem to be with how to change the value of a field, but how to get the table to recognize the change. I thought such things were automatic. The model fires a value changed event and the JTable picks up the event and refreshes. I'm not sure why your table is not refreshing under these circumstances. Perhaps a more complete code snippet. Please use the open and close code tags to format your code if you include it.
Similar Messages
-
How to delete the selected rows in a JTable on pressing a button?
How to delete the selected rows in a JTable on pressing a button?
You are right. I did the same.
Following is the code where some of them might find it useful in future.
jTable1.selectAll();
int[] array = jTable1.getSelectedRows();
for(int i=array.length-1;i>=0;i--)
DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
model.removeRow(i);
} -
How can I add a row into a JTable with JButton
Hi all. I have the following code:
package gui;
import db.*;
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
public class FoundersTable extends AbstractTableModel{
private static final int COLUMNS = 8;
private String columnNames[] = {"��� ����", "���", "�������", "�������", "���������", "��������",
"����� �� ����������", "������ �� ����, �����"};
private ArrayList data;
public FoundersTable(){
data = new ArrayList();
public int getRowCount() {
return data.size();
public int getColumnCount() {
return columnNames.length;
public String getColumnName(int colIndex) {
return columnNames[colIndex];
public Object getValueAt(int rowIndex, int columnIndex) {
return ((ArrayList)data.get(rowIndex)).get(columnIndex);
public void setValueAt(Object value, int rowIndex, int columnIndex) {
((ArrayList)data.get(rowIndex)).set(columnIndex, value);
fireTableCellUpdated(rowIndex, columnIndex);
public void addRow(ArrayList neueZeile) {
data.add(neueZeile);
int index = data.size() - 1;
fireTableRowsInserted(index, index);
public void removeRow(int index) {
data.remove(index);
fireTableRowsDeleted(index, index);
public void removeAllRows() {
data.clear();
fireTableRowsDeleted(0, 0);
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}Now in my MainJFrame class I have one button for additing and one button for removing a selected row. How can I add/remove rows with this two buttons.
ThanksNo my question is how can I add and remove rows WITH buttons My point was the code is the same. You use the addRow(...) method. Why did you write an addRow(...) method if you aren't going to use it?
I don't understand your problem. Do you not know how to write an ActionListener? -
How do you make the rows in a JTable uneditable.
Hi
Does anyone knows how to make the rows in a JTable uneditable.
--kirkHi,
implement a TableModel, e.g AbstractTableModel and use it to initialise
your table. (JTable aTable = new JTable(myAbstractTableModel))
And if you want your table to be editable implement isCellEditable() in your table model, and let it return true. If not let it return false, or don't implement it att all. -
How can I get a Row in a JTable?
I want to get the Last row in a JTable. How can I get it? Thanks.
something like
TableModel tm = table.getModel();
int rows = tm.getRowCount();
Object col0Value = tm.getValueAt(rows, 0);
Object col1Value = tm.getValueAt(rows,1);
... -
How to select a particular row in a JTable?
I want to select a particular row in a JTable. i.e something like
table.setSelectedRow(arg)how can i do it.You can use
table.getSelectionModel().setwhateverIsInTheAPI(...)
depending on your selection mode.Thanx,
but i don't want to change the selectionMode, i
want to select a particular row thro program.
This is like list.setSelected(index) in
JListThe original poster was pointing you in the right direction. You have to use the SelectionModel when you want to work with the selected indexes of a JTable. It will return a ListSelectionModel, which will be an instance of DefaultListSelectionModel unless you implemented your own. Refer to the API for the appropiate method(s).
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/ListSelectionModel.html -
How to disable a particular row in a JTable
How can a disable only a particular row/column in a JTable.
I am trying to create an XML Notepad type of application for which I need the row which contains the root element or any element which has a child element to be disabled. How can I achieve this??
I would be grateful for replies.Hi,
Create your own class which extends TableModel and in that class u override the method
public boolean isCellEditable( int row, int col)
As u know the row and col which u want to disable hard code those values in the method.
Like
public boolean isCellEditable( int row, int col)
if( row == 2 and col == 1 )
return false
else
return true
Hopefully this provides u with a solution.
Cheers :)
Nagaraj -
How can I make a row selected in JTable?
I want to make a row selected and highlighted in JTable programmatically.
But, I couldn't find method like setSelected(int row).
How can I do this?try this ....
private void makeRowVisible(JTable table, int row) {
java.awt.Rectangle cellRect = table.getCellRect(row, 0, true);
if (cellRect != null) {
table.scrollRectToVisible(cellRect);
} -
How to display all the rows in a JTable ???
Hi,
i want to display blank lines in a JTable if there is not enough rows to fill in it. For the moment, there is nothing in the JTable if i have nothing in my tables. Where am i wrong ??
Thanks !!hi,
use a contructor for jtable with the parameter rowcount or
define a tablemodel class extends from abstract tablemodel mit the method int getRowCount()
{ return xxx;}
table.setModel(mymodel); -
How can i add rows to a JTable at run time ??????
hi there
how can i add a row to a JTable at run time? and display the table after the change? thank you.For adding or removing the rows from the JTable, you have to use the methods on the table model. I would show you a simple implementation of table model.
public class MyTableModel extends AbstractTableModel {
private ArrayList rowsList = null;
private String [] columns = { "Column 1" , "Column 2", "Column 3"};
public MyTableModel() {
rowsList = new ArrayList();
public int getRowCount() {
return rowsList.size();
public int getColumnCount() {
return columns.length;
public void addRow(MyRow myRow) {
//MyRow is any of your object.
rowsList.add(myRow);
fireTableDataChanged();
public void removeRow(int rowIndex) {
rowsList.remove(rowIndex);
fireTableRowsDeleted(rowIndex, rowIndex);
public Object getValueAt(int row, in col) {
MyRow currentRow = (MyRow)rowsList.get(row);
switch (col) {
case 0:
//return the value of first cell
break;
case 1 :
//return the value of second cell
break;
case 2 :
//return the value of third cell
break;
}Then create the table using the TableModel using the constructor new JTable(TableModel) and then when you want to add/remove a row from the table, call myTableModel.addRow(MyRow) or myTableModel.removeRow(rowIndex)....I hope that this solves your problem. -
Delete multiple rows in a JTable ADF Swing.
hi guys,
Would anyone know tell me how do I delete multiple rows in a JTable ADF Swing?
JDeveloper.Hi,
I would configure the table for multi row selection. Then get the selected row index, access the iterator in the PageDef file (through the panelBinding reference you have in ADF Swing) and then iterate over the selected row indexes, make an index to become the current row and call remove() on it
Frank -
How can i remove a row from a JTable??
You need to extends AbstractTableModel rather than use DefaultTableModel as I think from memory this just uses an array to store data.
If you use a vector in your subclass to store your rows, then you can do something like this:
public boolean delete(int rowIndex)
if (rowIndex < 0 || rowIndex >= rowVector.size())
return false;
else
int day = 0;
MyRowClass row = rowVector.get(rowIndex);
rowVector.remove(rowIndex);
rowCount--;
fireTableRowsDeleted(rowIndex, rowIndex);
return true;
}HTH
Paul C. -
How to refresh the grid so that default values come on adding new row.
Hi Experts,
In alv grid while adding new row, i want some 2-3 column values to come by default from already existing row in grid.
i am getting new row in internal table with 2-3 default values and rest columns blank on adding new row in alv grid
but the entire row is coming blank, not able to get the default values in new row
how can i refresh the grid so that default values come on adding new row.
thanksHi Surabhi,
Use this in Interactive section even if you are doing simple ALV.
DATA:
lv_ref_grid TYPE REF TO cl_gui_alv_grid.
CLEAR : gv_tcode.
*-- to ensure that only new processed data is displayed
IF lv_ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lv_ref_grid.
ENDIF.
IF NOT lv_ref_grid IS INITIAL.
CALL METHOD lv_ref_grid->check_changed_data.
ENDIF.
THis will solve your problem.
Regards,
Vijay -
How to add new row and update existing rows at a time form the upload file
hi
How to add new row and update existing rows at a time form the upload file
example:ztable(existing table)
bcent smh nsmh valid date
0001112465 7.4 26.06.2007
0001112466 7.5 26.06.2007
000111801 7.6 26.06.2007
1982 7.8 26.06.2007
Flat file structure
bcent nsmh valid date
0001112465 7.8 26.06.2007 ( update into above table in nsmh)
0001112466 7.9 26.06.2007 ( update into above table in nsmh)
000111801 7.6 26.06.2007 ( update into above table in nsmh
1985 11 26.06.2007 new row it should insert in table
thanks,
Sivagopal RHi,
First upload the file into an internal table. If you are using a file that is on application server. Use open dataset and close dataset.
Then :
Loop at it.
*insert or modify as per your requirement.
Endloop.
Regards,
Srilatha. -
How to create new or delete the existing row in the grid....
hi my friends...
i am developing report using Reuse_alv_grid_display...
my requirement is... At runtime
1. i may create new row on the grid (empty row inwhich i may enter the data).
2. i may delete a existing row in the grid
3. i may edit the existing data...
then i have to trace the modification in the grid in one internal table...
how can i get into this.....
note:
i have some idea to edit the existing record in the grid and trace those modification,
but i don't know abt how to create new or delete the existing row....
can you give me some idea...Hi deva,
write a class which implemets these methods
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
To handle the toolbar on alv
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
To handle the buttons on the alv grid
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
endclass.
Now Implement these methods.
CLASS lcl_event_receiver IMPLEMENTATION.
To handle the toolbar on alv
METHOD handle_toolbar.
DATA ls_toolbar TYPE stb_button.
CLEAR gs_toolbar.
MOVE 3 TO gs_toolbar-butn_type.
APPEND gs_toolbar TO e_object->mt_toolbar.
CLEAR gs_toolbar.
PERFORM icon_create USING 'ICON_INSERT_ROW' gs_toolbar-icon.
MOVE text-010 TO gs_toolbar-function.
MOVE text-012 TO gs_toolbar-quickinfo.
MOVE ' ' TO gs_toolbar-disabled.
APPEND gs_toolbar TO e_object->mt_toolbar.
CLEAR gs_toolbar.
PERFORM icon_create USING 'ICON_DELETE_ROW' gs_toolbar-icon.
MOVE text-011 TO gs_toolbar-function.
MOVE text-013 TO gs_toolbar-quickinfo.
MOVE ' ' TO gs_toolbar-disabled.
APPEND gs_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command.
In this form, check the function code(e_ucomm has the function code), based on that do the required action.
as i said yesterday(i.e for appending a row, deleting a row, modifying a row)
PERFORM user_command USING e_ucomm.
ENDMETHOD
endclass.
Before calling the alv method, create a object of this class.
DATA :
gref_event_receiver TYPE REF TO lcl_event_receiver,
gv_tables_alv TYPE REF TO cl_gui_alv_grid.
CREATE OBJECT gref_event_receiver.
SET HANDLER gref_event_receiver->handle_user_command
FOR gv_tables_alv.
SET HANDLER gref_event_receiver->handle_toolbar
FOR gv_tables_alv.
check this program for event handling, it is the similar way
demo_abap_objects_events
Hope u understood this.
Regards,
Prasant
reward if helpful
Maybe you are looking for
-
Screen resolution when PXE boot from WDS vs Install Windows 8.1 from USB
Hi all I own a Lenovo ThinkPad T430s, X230 Tablet, and now have my hands on a T440. All three machines have UEFI Secure Boot enabled properly, i.e. Windows boot screen shows Lenovo logo instead of Windows logo. However, if I do a PXE boot (using Wind
-
SAP Servers not showing up in Server Explorer...
Hi, I have just installed v2 of NCO and everything has installed fine. Also tested a previous application written for v1 NCO and works fine. But for some reason or other I can no longer create a sapproxy with V2. I followed the tutorial in VS2003 to
-
Epson R1900 will not print or update
Can't get my R1900 to print. Utility see the printer and will tell me my ink level. But can't get it to print anything. Apples Epson update did nothing. Epson driver installers crash/quit after verifying password. Did the Rosetta thing, tried under s
-
How to get rid of a CSS style instance that is effecting the wrong page
I am new to CSS and I am working in Dreamweaver CC. I am mostly designing in the large screen view and then making my changes to the tablet and phone later. I have the large screen design finished, and now am making changes to the tablet size. I am
-
How to consume UME API in webdynpro applications
Hi , i want to consume the portal services in webdynpro applications. here i want to use UME Service . how to consume it my WD applications . isit the same way as described in the below link : [http://help.sap.com/saphelp_nw70/helpdata/en/d2/035742