嗨,我想在 DefaultTableModel 中显示新行,但我不知道为什么表不显示输入。如何启用输入?如果我有一个字符串“stss\nsdd”,它会显示“stsssdd”,但我想要换行。
public class Main extends JFrame {
DefaultTableModel model = new DefaultTableModel(
new Object[][]{{"some", "text"}, {"any", "text"},
{"even", "more"}, {"text", "str\nings"},
{"and", "other"}, {"text", "values"}}, new Object[]{
"Column 1", "Column 2"});
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTable table = new JTable(model);
table.setRowHeight(40);
getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
pack();
}
public static void main(String arg[]) {
new Main().setVisible(true);
}
}