P
poorichard
hi,all
I'd to start editing the cell at row and column programmatically,
the methond I used was JTable.editCellAt(row,col),
it's prepered for this,I think,
but there is something wrong,
the whole code as follows:
public class FrameTest {
Logger logger = Logger.getLogger(FrameTest.class.getName());
static int width = 500;
static int height = 300;
JFrame frame;
public FrameTest(){
logger.setLevel(Level.ALL);
createUI();
}
JTable table;
public void createUI(){
logger.fine("start createUI");
frame = new JFrame("TestFrame");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setPreferredSize(new Dimension(width,height));
initTable();
frame.add(new JScrollPane(table));
frame.pack();
frame.setVisible(true);
}
DefaultTableModel tableModel;
static final String[] columnNames = {"a","b","c","d","e","f","g","h"};
private void initTable(){
logger.fine("start initTable");
tableModel = new DefaultTableModel(columnNames,2);
table = new JTable(tableModel);
table.setRowSelectionAllowed(false);
table.requestFocusInWindow();
boolean isEditing = table.editCellAt(0, 1);
looger.info("is in editing?:"+isEditing);
}
public static void main(String[] args){
new FrameTest();
}
}
it can't work yet in my PC,
the envionment is Eclipse3.2 /3.1.2 and JDK1.5/1.6,
is there any wrong?
best regards,
Richard
I'd to start editing the cell at row and column programmatically,
the methond I used was JTable.editCellAt(row,col),
it's prepered for this,I think,
but there is something wrong,
the whole code as follows:
public class FrameTest {
Logger logger = Logger.getLogger(FrameTest.class.getName());
static int width = 500;
static int height = 300;
JFrame frame;
public FrameTest(){
logger.setLevel(Level.ALL);
createUI();
}
JTable table;
public void createUI(){
logger.fine("start createUI");
frame = new JFrame("TestFrame");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setPreferredSize(new Dimension(width,height));
initTable();
frame.add(new JScrollPane(table));
frame.pack();
frame.setVisible(true);
}
DefaultTableModel tableModel;
static final String[] columnNames = {"a","b","c","d","e","f","g","h"};
private void initTable(){
logger.fine("start initTable");
tableModel = new DefaultTableModel(columnNames,2);
table = new JTable(tableModel);
table.setRowSelectionAllowed(false);
table.requestFocusInWindow();
boolean isEditing = table.editCellAt(0, 1);
looger.info("is in editing?:"+isEditing);
}
public static void main(String[] args){
new FrameTest();
}
}
it can't work yet in my PC,
the envionment is Eclipse3.2 /3.1.2 and JDK1.5/1.6,
is there any wrong?
best regards,
Richard