how to make the JTable.editCellAt(row,col) work

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top