Several questions about JTable ~ ~

Category: Java SE
 
accpa255
2008-11-11 11:27:07

Sponsored Links
I. How to make JTable responsive?
When we added JTable data (such as the database of the INSERT operations), how to make an immediate update it? I tried validate () seems to not work. However, drag the Column, change the window size, etc. can make JTable react ~ ~ When we removed the data, the same problem will be temporary.
Two. To find the time, if the search result is a collection of them in a JTable wishing to selected manifested in the form, how it should be ~ ~ on a single result, you can use
DefaultListSelectionModel dsm = new DefaultListSelectionModel ( );
dsm.addSelectionInterval (RowiIndex, RowiIndex);
table.setSelectionModel (dsm);
or whether other methods do to. Seems addSelectionInterval () only single selection, multiple selection is not supported (MULTIPLE_INTERVAL_SELECTION)

contemplation ....


Sponsored Links

qqrto
2008-11-11 11:46:14
This monitoring can be done using Update Now, one thing but add to the list you can see ^ _ ^
import javax.swing. *;
import javax.swing.event. *;
public class MyTableModelListener implements TableModelListener {
JTable table;

; / / It is necessary to keep the table since it is not possible
/ / to determine the table from the event's source
MyTableModelListener (JTable table) {
this.table = table;
;}

public void tableChanged (TableModelEvent e) {
int firstRow = e.getFirstRow ();
int lastRow = e.getLastRow ();
; int mColIndex = e.getColumn ();

switch (e.getType ()) {
case TableModelEvent.INSERT:
/ / The inserted rows are in the range [firstRow, lastRow]
; for (int r = firstRow; r <= lastRow; r + +) {
/ / Row r was inserted
;}
break;
case TableModelEvent.UPDATE:
if (firstRow == TableModelEvent.HEADER_ROW) {
if (mColIndex == ; TableModelEvent.ALL_COLUMNS) {
/ / A column was added
;} else {
; / / Column mColIndex in header changed
}
;} else {
; / / The rows in the range [firstRow, lastRow] changed
; for (int r = firstRow; r <= lastRow ; r + +) {
/ / Row r was changed

; if (mColIndex == TableModelEvent.ALL_COLUMNS) {
; ; / / All columns in the range of rows have changed
} else {
/ / Column mColIndex changed
;}
}
}
break;
case TableModelEvent.DELETE:
/ / The rows in the range [firstRow, lastRow] changed
for (int r = firstRow; r <= lastRow; r + +) {
; / / Row r was deleted
}
; break;
}
}
}

when used private MyTableModelListener chang = new MyTableModelListener (jTable1);
qqq___
2008-11-11 12:03:19
TableModel can provide their own
{
....
myTableModel mtm = new myTableModel (..);
jTable.setModel (mtm);

....
myTableModel tm = (myTableModel) jTable . getModel ();
tm.changeData (..);

}

class myTableModel extends AbstractTableModel {
public void changeData (...) {
/ / modify data
fireTableDataChanged ();
}

}
lxy521czw
2008-11-11 12:10:12
updateUI () okay?
hzaode
2008-11-11 12:26:07
TableModel generate the object, add a JTable in
wzg005
2008-11-11 12:40:35
updateUI () line ah ~ ~ ft ~ ~ how would not try it yourself first ~ ~ ~
simyu29
2008-11-11 12:56:59
to fatboyslim ~ ~ ~:
my practice test private class DataModel extends AbstractTableModel. This seems to be a lot simpler ~ ~ Because AbstractTableModel already for us to achieve a lot of functionality, it can greatly improve the productivity of the crash (advertising phrase, Oh ~ ~) ~ ~
ABCDHIJ
2008-11-11 01:10:51
me because they have ready this class, so every time, huh, huh. Only consolation, Ah Q is in fact what
asked a similar question csdn cow told me
YGTQYYY
2008-11-11 01:13:49
We then help solve the second wt it ~ ~ ~ 3ku ~ ~
turtlesfamily
2008-11-11 01:23:57
to winter_sui (head with a bag)
can put a little more detail is given the best source ~ ~
maoguangfu
2008-11-11 01:34:02
to the landlord
I am now busy looking for work, and other days I have my say. . .
hope forgive me. . . . . . . . . . . . . . . . . .
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.