Java Swing JLabel未出现

Java Swing JLabel未出现,java,swing,jpanel,jlabel,Java,Swing,Jpanel,Jlabel,JLabel名称标签将不会出现在gui上。我尝试使用SwingWorker,因此并发性不是问题。当Jlabel添加到内部JPanel的BorderLayout的西段时,面板为标签腾出空间,但标签实际上没有出现。如果有人有这个问题或知道如何解决它,我将非常感激 谢谢 public class Frame_2 { JButton done = new JButton("Next Page"); JLabel topLabel = new JLabel("2. Contact Inf

JLabel名称标签将不会出现在gui上。我尝试使用SwingWorker,因此并发性不是问题。当Jlabel添加到内部JPanel的BorderLayout的西段时,面板为标签腾出空间,但标签实际上没有出现。如果有人有这个问题或知道如何解决它,我将非常感激

谢谢

public class Frame_2 
{
    JButton done = new JButton("Next Page");
    JLabel topLabel = new JLabel("2. Contact Information");

    JTextField nameInput = new JTextField();
    JTextField mailingAddressInput = new JTextField();
    JTextField cityStateInput = new JTextField();
    JTextField telephoneInput = new JTextField();
    JTextField faxInput = new JTextField();
    JTextField eMailInput = new JTextField();

    JLabel nameLabel = new JLabel("Name:");

    JPanel internal = new JPanel();
    JPanel northGrid = new JPanel();


    int keepTrack = 0;

    String name;
    String mailingAddress;
    String cityState;
    String telephone;
    String fax;
    String eMail;

    public void buildFrame_2(JFrame frame)
    {
        nameLabel.setText("Name:");
        nameInput.setText("Name:");
        mailingAddressInput.setText("Mailing Address:");
        cityStateInput.setText("City, State, Zip Code:");
        telephoneInput.setText("Telephone:");
        faxInput.setText("Fax:");
        eMailInput.setText("E-mail:");
        internal.setLayout(new BorderLayout());
        topLabel.setHorizontalAlignment(SwingConstants.CENTER);
        frame.setLayout(new BorderLayout());
        northGrid.setLayout(new GridLayout(12,2));

        nameInput.addActionListener((new ActionListener()
        {

            public void actionPerformed(ActionEvent e) 
            {
                    name = nameInput.getText();
                    System.out.println(name);
                    nameInput.setVisible(false);
                    keepTrack++;
                    if(keepTrack == 6)
                    {
                        askForSecondary(internal);
                    }
            }
        }));    


        mailingAddressInput.addActionListener((new ActionListener()
        {

            public void actionPerformed(ActionEvent e) 
            {
                    mailingAddress = mailingAddressInput.getText();
                    System.out.println(mailingAddress);
                    mailingAddressInput.setVisible(false);
                    keepTrack++;
                    if(keepTrack == 6)
                    {
                        askForSecondary(internal);
                    }
            }
        }));        
        cityStateInput.addActionListener((new ActionListener()
        {

            public void actionPerformed(ActionEvent e) 
            {
                    cityState = cityStateInput.getText();
                    System.out.println(cityState);
                    cityStateInput.setVisible(false);
                    keepTrack++;
                    if(keepTrack == 6)
                    {
                        askForSecondary(internal);
                    }
            }
        }));    
        telephoneInput.addActionListener((new ActionListener()
        {

            public void actionPerformed(ActionEvent e) 
            {
                    telephone = telephoneInput.getText();
                    System.out.println(telephone);
                    telephoneInput.setVisible(false);
                    keepTrack++;
                    if(keepTrack == 6)
                    {
                        askForSecondary(internal);
                    }
            }
        }));    
        faxInput.addActionListener((new ActionListener()
        {

            public void actionPerformed(ActionEvent e) 
            {
                    fax = faxInput.getText();
                    System.out.println(fax);
                    faxInput.setVisible(false);
                    keepTrack++;
                    if(keepTrack == 6)
                    {
                        askForSecondary(internal);
                    }
            }
        }));    
        eMailInput.addActionListener((new ActionListener()
        {

            public void actionPerformed(ActionEvent e) 
            {
                    eMail = eMailInput.getText();
                    System.out.println(eMail);
                    eMailInput.setVisible(false);
                    keepTrack++;
                    if(keepTrack == 6)
                    {
                        askForSecondary(internal);
                    }
            }
        }));    

        northGrid.add(nameInput);
        northGrid.add(mailingAddressInput);
        northGrid.add(cityStateInput);
        northGrid.add(telephoneInput);
        northGrid.add(faxInput);
        northGrid.add(eMailInput);

        internal.add(nameLabel, BorderLayout.WEST);

        //internal.add(northGrid, BorderLayout.CENTER);



        frame.add(internal, BorderLayout.CENTER);
        frame.add(done, BorderLayout.SOUTH);
        frame.add(topLabel, BorderLayout.NORTH);

    }

使用下面的代码,标签对我来说很好

JFrame f = new JFrame();
Frame_2 f2 = new Frame_2();
f2.buildFrame_2(f);
f.pack();
f.setVisible(true);
但是,如果删除了
pack()
调用,框架默认为其最小大小,因此无法看到内容


我的猜测是,您只需要调整帧的大小。但是,如果您想要更准确的答案,您确实应该提供SSCCE。

谢谢您的帮助。实际上,我的框架比pack()允许的大,即使我调用pack,标签也不会显示出来。我在这个标签出现之前添加的所有内容,但由于我尝试添加标签,其他内容都不会显示。我添加了一个测试按钮,它在点击后才会显示在屏幕上。在这种情况下,我建议更新您的问题,以包含一个编译和演示问题的小代码示例。