现在我有以下代码将 JLabel 添加到面板的顶部中心,我认为这是默认设置
imageLabel = new JLabel();
ImageIcon customer1 = new ImageIcon("src/view/images/crab.png");
imageLabel.setIcon(customer1);
storePanel.add(imageLabel);
imageLabel.setBounds(20, 20, 50, 50);
setBounds 显然不会把它放在 20,20 ....那么你如何将某些东西定位到 Panel 中的一个点?
最佳答案
使用适当的 LayoutManager 在面板中放置组件。
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
在您的情况下,您应该能够使用 FlowLayout
并在创建它时设置水平和垂直间距。
http://docs.oracle.com/javase/7/docs/api/java/awt/FlowLayout.html#FlowLayout(int,%20int,%20int)
关于java - 如何在 JPanel 的某个点上定位某些东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20201158/