如何在JavaSwing中添加新行?

a11xaf1n  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(217)

所以我有这个密码:

heading = new JLabel("   Club Registration Form   ");
    heading.setForeground(Color.yellow);
    name = new JLabel(" Student Name: \n");
    name.setForeground(Color.white);
    yearLevel = new JLabel("<html><p> Year Level: </p></html>");
    yearLevel.setForeground(Color.white);
    section = new JLabel(" Section: ");
    section.setForeground(Color.white);
    club = new JLabel(" Preferred Club: ");
    club.setForeground(Color.white);
    nameForm = new JTextField(8);
    yearLevelForm = new JTextField(8);
    sectionForm = new JTextField(8);
    clubForm = new JTextField(8);

    submit = new JButton("Submit");

    add(heading, BorderLayout.CENTER);
    System.out.println("\n");
    add(name);
    add(nameForm);
    add(yearLevel);
    add(yearLevelForm);
    add(section);
    add(sectionForm);
    add(club);
    add(clubForm);
    add(submit);

如你所见,我试过 \n ,html方法和print方法。我希望它看起来像这样:

文本字段有自己的行
它总是出现在一行中。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题