鱼C论坛

 找回密码
 立即注册
查看: 3918|回复: 1

[已解决]JTable 组件

[复制链接]
发表于 2021-3-29 21:29:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
每当添加表格是就报数组下标越界,请问是什么问题???
import javax.swing.*;
import java.awt.*;

public class Demo extends JFrame{
        public Demo() {
                setVisible(true);
                setBounds(500, 200, 200, 300);
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                Container c = getContentPane();
                
                String[] clumnname = {"A","B","C"};
                String[][] into = {{"A1","A2"},{"B1","B2"},{"C1","C2"}};
                
                JTable table = new JTable(into, clumnname);
                JScrollPane jp = new JScrollPane(table);
                c.add(jp);
        }
        public static void main(String[] args) {
                new Demo();
        }
}
错误信息
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2
        at java.desktop/javax.swing.JTable$1.getValueAt(Unknown Source)
        at java.desktop/javax.swing.JTable.getValueAt(Unknown Source)
        at java.desktop/javax.swing.JTable.prepareRenderer(Unknown Source)
        at java.desktop/javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
        at java.desktop/javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
        at java.desktop/javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
        at java.desktop/javax.swing.plaf.ComponentUI.update(Unknown Source)
        at java.desktop/javax.swing.JComponent.paintComponent(Unknown Source)
        at java.desktop/javax.swing.JComponent.paint(Unknown Source)
        at java.desktop/javax.swing.JComponent.paintChildren(Unknown Source)
        at java.desktop/javax.swing.JComponent.paint(Unknown Source)
        at java.desktop/javax.swing.JViewport.paint(Unknown Source)
        at java.desktop/javax.swing.JComponent.paintChildren(Unknown Source)
        at java.desktop/javax.swing.JComponent.paint(Unknown Source)
        at java.desktop/javax.swing.JComponent.paintChildren(Unknown Source)
        at java.desktop/javax.swing.JComponent.paint(Unknown Source)
        at java.desktop/javax.swing.JComponent.paintChildren(Unknown Source)
        at java.desktop/javax.swing.JComponent.paint(Unknown Source)
        at java.desktop/javax.swing.JLayeredPane.paint(Unknown Source)
        at java.desktop/javax.swing.JComponent.paintChildren(Unknown Source)
        at java.desktop/javax.swing.JComponent.paintToOffscreen(Unknown Source)
        at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBufferedImpl(Unknown Source)
        at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
        at java.desktop/javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
        at java.desktop/javax.swing.RepaintManager.paint(Unknown Source)
        at java.desktop/javax.swing.JComponent.paint(Unknown Source)
        at java.desktop/java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
        at java.desktop/sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
        at java.desktop/sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
        at java.desktop/java.awt.Container.paint(Unknown Source)
        at java.desktop/java.awt.Window.paint(Unknown Source)
        at java.desktop/javax.swing.RepaintManager$4.run(Unknown Source)
        at java.desktop/javax.swing.RepaintManager$4.run(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at java.desktop/javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
        at java.desktop/javax.swing.RepaintManager.access$1200(Unknown Source)
        at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
        at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.desktop/java.awt.EventQueue.access$600(Unknown Source)
        at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
        at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
最佳答案
2021-4-5 21:20:05
本帖最后由 夏雨莲 于 2021-4-5 21:23 编辑

你的表头的列数和表中的数据的列数不同,你的表头是三列,表中的数据是2列,你把它们改成相同的列数就行了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-5 21:20:05 | 显示全部楼层    本楼为最佳答案   
本帖最后由 夏雨莲 于 2021-4-5 21:23 编辑

你的表头的列数和表中的数据的列数不同,你的表头是三列,表中的数据是2列,你把它们改成相同的列数就行了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-22 18:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表