Skip to content

Commit d27532f

Browse files
committed
修复切换分组时,会导致下标越界异常问题。
1 parent bc5036b commit d27532f

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/main/java/com/sjhy/plugin/ui/AbstractGroupPanel.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<E>, E> {
8282

8383
/**
8484
* 构造方法
85-
* @param group 分组映射对象
85+
*
86+
* @param group 分组映射对象
8687
* @param selectGroupName 当前选中的分组名称
8788
*/
8889
public AbstractGroupPanel(Map<String, T> group, String selectGroupName) {
@@ -157,6 +158,10 @@ private void initItem() {
157158
itemGroupPanel.add(button);
158159
});
159160
itemGroupPanel.updateUI();
161+
// 修复下标越界异常
162+
if (selectItemIndex >= elementList.size()) {
163+
selectItemIndex = 0;
164+
}
160165
//初始化第一个元素面板
161166
initItemPanel(itemPanel, elementList.get(selectItemIndex));
162167
initFlag = true;
@@ -263,7 +268,7 @@ private void initEvent() {
263268
if (result == JOptionPane.YES_OPTION) {
264269
itemList.remove(selectItemIndex);
265270
// 移步到当前删除元素的前一个元素
266-
if (selectItemIndex>0) {
271+
if (selectItemIndex > 0) {
267272
selectItemIndex--;
268273
}
269274
initItem();
@@ -301,27 +306,31 @@ private void initEvent() {
301306

302307
/**
303308
* 初始化元素面板
309+
*
304310
* @param itemPanel 父面板
305-
* @param item 元素对象
311+
* @param item 元素对象
306312
*/
307313
protected abstract void initItemPanel(JPanel itemPanel, E item);
308314

309315
/**
310316
* 获取元素名称
317+
*
311318
* @param item 元素对象
312319
* @return 元素名称
313320
*/
314321
protected abstract String getItemName(E item);
315322

316323
/**
317324
* 设置元素名称
318-
* @param item 元素对象
325+
*
326+
* @param item 元素对象
319327
* @param itemName 元素名称
320328
*/
321329
protected abstract void setItemName(E item, String itemName);
322330

323331
/**
324332
* 创建元素
333+
*
325334
* @param name 元素名称
326335
* @return 元素对象
327336
*/

0 commit comments

Comments
 (0)