I'm trying to add my toString() method of Person class to a GUI:
public GUI_Persons() {
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JTextPane textPane = new JTextPane();
textPane.setBounds(0, 38, 434, 223);
for(Person person : Access.getAllPersons()) {
textPane.setText(textPane.getText() + person.toString() + "\n");
}
contentPane.add(textPane);
JLabel lblAllPersons = new JLabel("All persons information");
lblAllPersons.setBounds(10, 11, 188, 16);
contentPane.add(lblAllPersons);
}
Unfortunaley, only a blank text field is shown. Does somebody have an idea why the text won't be set to the JTextPane component? I also use a method run, because this frame shows up if a user hits the "view persons" button in another frame:
public static void run() {
try {
GUI_Persons frame = new GUI_Persons();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
This is the toString() method:
public String toString()
{
return "ID: " + id + ", Type: " + this.getClass().getSimpleName() +", Name: " + name + ", Forename: " + forename + ", Adress: " + adr.toString();
}
Thanks for all information in advance.