本文介绍了将jlabels添加到jframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在向JFrame添加超过1个JLabel数组时遇到问题



我尝试了什么:



I'm having an issue adding more than 1 of my JLabel array to my JFrame

What I have tried:

public JLabel[] createLabels()
    {
        for(int i = 0; i < 16; i++)
        {
          pnlBoard.add(new JLabel("1"));
          pnlBoard.add(new JLabel("2"));
          pnlBoard.add(new JLabel("3"));
          pnlBoard.add(new JLabel("4"));
          pnlBoard.add(new JLabel("5"));
          pnlBoard.add(new JLabel("6"));
          pnlBoard.add(new JLabel("7"));
          pnlBoard.add(new JLabel("8"));
        }
        return null;
    }

推荐答案

Quote:

我在向JFrame添加超过1个JLabel数组时遇到问题

I'm having an issue adding more than 1 of my JLabel array to my JFrame



尝试描述问题。



您的代码可以简化为:


Try to describe the issue.

Your code can be simplified to:

public JLabel[] createLabels()
    {
        JLabel[] l = new JLabel[16];

        for(int i = 0; i < 16; i++)
        {







          l[i] = new JLabel("8");
        }
        return l;
    }



,结果相同。


with same result.


这篇关于将jlabels添加到jframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 16:05
查看更多