Hello guys,
I have one iFrame where I can enter a number x. After that, it creates a new JDialog. In this Jdialog, I want to create x JPanels in a matrix, but it does not work. This is my code:
public TeilnehmerDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); myViewController = new ViewController(); int eingabe = myViewController.getTeilnehmer(); String test = Integer.toString(eingabe); String prnr = "Prüfungsnummer: "; String name = "Name: "; JLabel[] jlabelsprnr = new JLabel[eingabe]; for (int i = 0; i < eingabe; i++) { jlabelsprnr[i] = new JLabel(prnr); } int GRID_ROWS = 2; int GRID_COLS = 2; GridBagLayout gbl = new GridBagLayout(); setLayout(gbl); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 0.2; gbc.weighty = 0.25; gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(5,5,5,5); //space that a container must levea at ech of its edges (to the border) gbc.gridwidth = 1; gbc.gridheight = 1; int index = 0; for (int i = index; i < eingabe; i++) { for (int row = 0; row < GRID_ROWS; row++) { for (int col = 0; col < GRID_COLS; col++) { gbl.setConstraints(jlabelsprnr[index], gbc); add(jlabelsprnr[index]); jlabelsprnr[index].setVisible(true); System.out.println(jlabelsprnr[index].getText()); // index++; } } } }
and this is my output:
for entering number 4!run: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer: Prüfungsnummer:
Thank you