我遇到了这个问题。我有一个JPanel,通常我会像这样创建一个JLabel:JLabellblNewLabel=newJLabel("Newlabel");lblNewLabel.setBounds(0,0,135,14);panel.add(lblNewLabel);但我希望每次单击一个按钮时,在该面板中创建一个具有相同大小但具有不同高度位置的新JLabel。我试过:panel.add(newJLabel(stringName));但这样我就无法设置它的界限。我从JTextField获得的stringName。 最佳答案 首先,使
我在JPanel中有许多JLabel(包括ImageIcon)。而这个JPanel只是GUI上的一个面板;还有很多其他面板。我想将标签放置到它们的JPanel容器上的精确像素坐标。如何在不使用GroupLayout的情况下做到这一点? 最佳答案 参见DoingWithoutaLayoutManager(AbsolutePositioning)在Java教程中。Creatingacontainerwithoutalayoutmanagerinvolvesthefollowingsteps.Setthecontainer'slayout
JPanelpMeasure=newJPanel();....JLabeleconomy=newJLabel("Economy");JLabelregularity=newJLabel("Regularity");pMeasure.add(economy);pMeasure.add(regularity);...当我运行上面的代码时,我得到了这个输出:EconomyRegularity我怎样才能得到这个输出,其中每个JLabel都在一个新行开始?谢谢EconomyRegularity 最佳答案 你会想要玩弄layoutmanager