为什么在JTable中没有标题显示?
我在defaultTableModel
中添加了一些行,但没有显示其中一个。我的问题是 - 问题是什么?在我看来,Intellij的想法只是在对我开个玩笑。
public class Main extends JFrame {
public Main(){
this.setLayout(null);
JTable table = new JTable();
table.setBounds(20,100,330,300);
table.setBackground(Color.pink);
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
dtm.addRow(new Object[]{"player1", "player2"});
dtm.addRow(new Object[]{"player"});
dtm.addRow(new Object[]{"player"});
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
add(table);
this.setBounds(100,100,500,500);
this.setVisible(true);
}
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
EventQueue.invokeLater(Main::new);
}
}
I added some rows to a DefaultTableModel
, but none of them was shown. My question is - what is the problem? It seems to me like Intellij idea just playing a joke on me.
public class Main extends JFrame {
public Main(){
this.setLayout(null);
JTable table = new JTable();
table.setBounds(20,100,330,300);
table.setBackground(Color.pink);
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
dtm.addRow(new Object[]{"player1", "player2"});
dtm.addRow(new Object[]{"player"});
dtm.addRow(new Object[]{"player"});
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
add(table);
this.setBounds(100,100,500,500);
this.setVisible(true);
}
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
EventQueue.invokeLater(Main::new);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多原因。这是一个可运行的可演示您如何做到的。在代码中读取评论:
可运行的产生以下内容:
可运行的代码:
There are a number of reasons. Here is a runnable that demonstrates how you can do it. Read the comments in code:
The runnable produces this:
The runnable code: