You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何在LayeredPane上按索引查找容器无法放置标签?

问题:LayeredPane按索引添加组件时抛出索引越界异常
  • 在设置类MovebyDrag中,可成功在LayeredPane的索引6位置放置标签,但回放(查看类)操作时抛出异常:java.lang.IndexOutOfBoundsException: Index 6 out of bounds for length 0
  • 该LayeredPane采用2×1表格布局:第一行是高度约束为6%的控制容器,第二行是字段;初始测试用3×4网格,最终网格单元数将是另一个Container(field)的两倍

已实现的成功案例(玩家标签回放)

读取数据库记录的索引位置(142),将玩家标签添加到monitor窗体的Container(field)中,代码如下:

tlwloc = currentRow.getString(5); // location for LW label returned from pandr.db
tlwloci = Integer.parseInt(tlwloc);
((Container) field.getComponentAt(tlwloci)).add(lwlbl);

出问题的球标签回放代码

尝试用相同逻辑处理球标签:数据库记录的容器索引为6,要将球标签添加到窗体顶层的LayeredPane(gls)中,代码如下:

tbloc = currentRow.getString(4);// location for ball label returned from pandr.db
tbloci = Integer.parseInt(tbloc);
((Container) gls.getComponentAt(tbloci)).add(blbl);

疑问

  1. 该异常是否因LayeredPane不被识别为Container导致索引查找失败?
  2. 是否有成功在LayeredPane上按索引查找容器的案例?

内容的提问来源于stack exchange,提问作者curtjacobs1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 05:52:03