Java:JLabels没有出现/ JCheckbox出现和消失

时间:2015-08-20 07:38:36

标签: java swing user-interface jpanel jcheckbox

我一直在制作一个程序,用Java存储学生的记录。如果我尝试创建一个记录,第一个按照计划完成。但是,当我尝试创建第二个时,只显示复选框,它会在调整窗口大小时消失并重新出现。

以下是创建新记录的代码:

JLabel[] DateRecord = new JLabel[99];
JLabel[] NameRecord = new JLabel[99];
JLabel[] ReasonRecord = new JLabel[99];
JCheckBox[] ConfirmedRecord = new JCheckBox[99];
JPanel[] Records = new JPanel[99];

int CurrentRecord = i++;
int Currenty = CurrentRecord*50;

Records[CurrentRecord] = new JPanel();
DateRecord[CurrentRecord] = new JLabel(date);
NameRecord[CurrentRecord] = new JLabel(name);
ReasonRecord[CurrentRecord] = new JLabel(reason);
ConfirmedRecord[CurrentRecord] = new JCheckBox();

ConfirmedRecord[CurrentRecord].setEnabled(true);

Records[CurrentRecord].setLayout(null);

int reasonlength = reason.length() * 3;

DateRecord[CurrentRecord].setBounds(80, 0, 200, 50);
NameRecord[CurrentRecord].setBounds(270, 0, 200, 50);
ReasonRecord[CurrentRecord].setBounds(770 - reasonlength, 0, 400, 50);
ConfirmedRecord[CurrentRecord].setBounds(1220, 13, 25, 50);

Records[CurrentRecord].add(DateRecord[CurrentRecord]);
Records[CurrentRecord].add(NameRecord[CurrentRecord]);
Records[CurrentRecord].add(ReasonRecord[CurrentRecord]);
Records[CurrentRecord].add(ConfirmedRecord[CurrentRecord]);

Records[CurrentRecord].setBounds(0, Currenty, (int) ((int) GUI.screenSize.width / 1.215), (int) GUI.screenSize.height - 113);

GUI.TablePanel.setLayout(null);
GUI.TablePanel.add(Records[CurrentRecord]);
GUI.TablePanel.repaint();
GUI.frame.repaint();

我在网上搜索,但一无所获。 任何帮助将不胜感激!

PS:我使用的是Java 7

-Qo2770

0 个答案:

没有答案