public void addSymbol_EveryLine(JTable table, String symbol) {
int RowTemp = table.getRowCount();
table.setValueAt(table.getValueAt(RowTemp - 1, 1).toString() + symbol,
(RowTemp - 1), 1);
}
}
目的是点击JButton按钮,JTable指定的单元格内的内容就会追加特定的符号。
比如说:表格为2行2列。第2行的第2列的内容为:hello。假设symbol=“world”。点击按钮后,第2行的第2列的内容应该更新为“helloworld”.
int RowTemp = table.getRowCount();
table.setValueAt(table.getValueAt(RowTemp - 1, 1).toString() + symbol,
(RowTemp - 1), 1);
}
}
目的是点击JButton按钮,JTable指定的单元格内的内容就会追加特定的符号。
比如说:表格为2行2列。第2行的第2列的内容为:hello。假设symbol=“world”。点击按钮后,第2行的第2列的内容应该更新为“helloworld”.
楼主【lirenhong0108】截止到2008-07-01 16:14:09的历史汇总数据(不包括此帖):
发帖数:5 发帖分:90
结贴数:2 结贴分:20
未结数:3 未结分:70
结贴率:40.00 % 结分率:22.22 %
楼主该结一些帖子了
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;public class MyTest extends JFrame {
private JTable table = new JTable(); private JButton btn = new JButton(); public MyTest() {
TableModel dataModel = new DefaultTableModel() {
public int getColumnCount() {
return 2;
} public int getRowCount() {
return 2;
}
};
this.table = new JTable(dataModel);
JScrollPane scrollpane = new JScrollPane(this.table);
Container contentPane = this.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(scrollpane, BorderLayout.CENTER); this.btn = new JButton("ControlButton");
contentPane.add(this.btn, BorderLayout.SOUTH);
this.btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addSymbol_EveryLine(MyTest.this.table, "World");
}
});
} public void addSymbol_EveryLine(JTable table, String symbol) {
int RowTemp = table.getRowCount();
Object value = table.getValueAt(RowTemp - 1, 1);
if (value != null) {
table.setValueAt(value.toString() + symbol, (RowTemp - 1), 1);
} else {
table.setValueAt(symbol, (RowTemp - 1), 1);
}
} /**
* @param args
*/
public static void main(String[] args) {
MyTest frame = new MyTest();
frame.setVisible(true);
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}