0

I have been working on a program to store Records on students in Java. If I try to create a Record, the first one works exactly as planned. However, when I try to create the second one, only the Checkbox appears, and it will disappear and reappear randomly while resizing the window.

Here is the code for creating a new Record:

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();

I have search the web, but found nothing. Any help would be appreciated!

PS: I am using Java 7

-Qo2770

  • 2
    Avoid using `null` layouts, pixel perfect layouts are an illusion within modern ui design. There are too many factors which affect the individual size of components, none of which you can control. Swing was designed to work with layout managers at the core, discarding these will lead to no end of issues and problems that you will spend more and more time trying to rectify – MadProgrammer Aug 20 '15 at 07:39
  • 1
    Consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This is not a code dump, but an example of what you are doing which highlights the problem you are having. This will result in less confusion and better responses – MadProgrammer Aug 20 '15 at 07:39
  • 1
    `Records[CurrentRecord].setLayout(null);` Yep. That'll produce the result mentioned in the title. Or rather, that is ***some*** of the crap the user will have to put up with unless the app. uses layouts. The solution of course, is to **use layouts** (with appropriate borders and layout padding for white space). – Andrew Thompson Aug 20 '15 at 08:40
  • Please learn common Java nomenclature (naming conventions - e.g. `EachWordUpperCaseClass`, `firstWordLowerCaseMethod()`, `firstWordLowerCaseAttribute` unless it is an `UPPER_CASE_CONSTANT`) and use it consistently. – Andrew Thompson Aug 20 '15 at 08:40
  • I made a post on pastebin with my code, merging two classes (WARNING! Not finished or perfect) : http://pastebin.com/iZJEZTb2 – Quentin Oschatz Aug 20 '15 at 09:11

0 Answers0