嘿,我在尝试让我的 jlabel 按照我想要的方式排列时遇到了一些麻烦。我使用 3 个面板(标题面板、显示面板和按钮面板) 在我的 DisplayPanel 内部我有一个 JtextField、3 个 jlabel,接下来我想要发生的事情是我的其余 JLabels 恰好是 ImageIcons在我的面板内的固定位置(位于 boxLayout 中)。
MasterOffense1 = new JLabel(Mastery1);
MasterOffense1.setLocation(400, 100);
MasterOffense1.setSize(25, 25);
MasterOffense1.setToolTipText("<html>"+"Double-Edged Sword<br> Melee- Deal an additional 2% damage and receive an additional 1% damage<br> Ranged- Deal and additional 1.5% damage and receive an additional 1.5% damage"+"</html>");
DisplayPanel.add(MasterOffense1);
MasterOffense2 = new JLabel(Mastery2);
MasterOffense2.setLocation(400, 130);
MasterOffense2.setSize(25,25);
MasterOffense2.setToolTipText("<html>"+"Fury<br> Rank-1: +1.25% Attack Speed<br> Rank-2: +2.5% Attack Speed<br> Rank-3: +3.75% Attack Speed<br> Rank-Max: +5.00% Attack Speed"+"</html>");
DisplayPanel.add(MasterOffense2);
有 2 个 JLabels 的代码,其中包含 ImageIcon,并且它们一直显示在彼此的正下方。我不知道如何实现这一点,我完全被难住了。 任何帮助,将不胜感激。谢谢!
最佳答案
There is code for the 2 JLabels with ImageIcon inside them and they keep showing up right below each other.
那么听起来您正在使用vertical BoxLayout
。
如果您希望标签水平显示,则可以将标签添加到面板,然后将该面板添加到“displayPanel”。
也就是说,您可以嵌套使用不同布局管理器的面板来获得所需的布局。
此外,请使用标准 Java 变量名称。变量名称不应以大写字符开头。
关于java - 在 java 中使用 BoxLayout 管理器和 JLabels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23331308/