gpt4 book ai didi

java - 程序中面临以下错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:38:26 25 4
gpt4 key购买 nike

jTable1 = new javax.swing.JTable();
String columns[]={"ID","Subject","Author","Type"};
jTable1.setModel(new javax.swing.table.DefaultTableModel(this.arr,columns));

jTable1.setName("jTable1"); // NOI18N

jTable1.addAncestorListener(new javax.swing.event.AncestorListener() {
public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
}
public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
jTable1AncestorAdded(evt);
}
public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
}
});

jScrollPane1.setViewportView(jTable1);

在这段代码中,一切都很好,但它没有在 jtable 中打印任何内容。即使我已经检查过该数组不包含空值并且它包含其中的值。没有语法错误。谁能告诉我这段代码不在表中显示数据的原因是什么?

最佳答案

不太确定您收到的错误是什么。

但是通过添加这样的 stub 数组:

static String[][] arr = {
{ "some Id1", "some subject1", "some author1", "some type1" },
{ "some Id2", "some subject2", "some author2", "some type2" } };

您的程序如下所示:

import javax.swing.*;
import javax.swing.event.AncestorEvent;
import javax.swing.table.DefaultTableModel;

class Test {
static String[][] arr = {
{ "some Id1", "some subject1", "some author1", "some type1" },
{ "some Id2", "some subject2", "some author2", "some type2" } };

public static void main(String[] args) {
JTable jTable1 = new javax.swing.JTable();
String columns[]={"ID","Subject","Author","Type"};
jTable1.setModel(new DefaultTableModel(arr,columns));
jTable1.setName("jTable1"); // NOI18N

jTable1.addAncestorListener(new javax.swing.event.AncestorListener() {
public void ancestorMoved(AncestorEvent evt) {}
public void ancestorAdded(AncestorEvent evt) {
//jTable1AncestorAdded(evt);
}
public void ancestorRemoved(AncestorEvent evt) {}
});

JScrollPane jScrollPane1 = new JScrollPane();
jScrollPane1.setViewportView(jTable1);

JFrame f = new JFrame();
f.setContentPane(jScrollPane1);
f.pack();
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

enter image description here

关于java - 程序中面临以下错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5870555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com