简体   繁体   English

在Java中将BoxLayout Manager与JLabels结合使用

[英]Using BoxLayout manager with JLabels in java

Hey all I am having some trouble trying to get my jlabels to line up the way I want them to. 嘿,我在尝试让jlabel排列我希望它们的方式时遇到了一些麻烦。 I am using 3 panels (Title Panel, Display Panel, and Button Panel) Inside of my DisplayPanel I have a JtextField, 3 jlabels and the next thing I want to have happen is for the rest of my JLabels which happen to be ImageIcons to be in a set location inside of my panel, which is in boxLayout. 我正在使用3个面板(标题面板,显示面板和按钮面板)在我的DisplayPanel中,我有一个JtextField,3个jlabel,接下来要发生的事情是其余的JLabel,它们恰好是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);

There is code for the 2 JLabels with ImageIcon inside them and they keep showing up right below each other. 其中包含两个带有ImageIcon的JLabel的代码,它们始终显示在彼此的正下方。 I have no idea how to make this happen and I am completely stumped.. Any help would be appreciated. 我不知道如何做到这一点,我完全陷入了困境。任何帮助,我们将不胜感激。 Thanks! 谢谢!

There is code for the 2 JLabels with ImageIcon inside them and they keep showing up right below each other. 其中包含两个带有ImageIcon的JLabel的代码,它们始终显示在彼此的正下方。

Then is sounds like you are using a vertical BoxLayout . 然后听起来好像您正在使用vertical BoxLayout

If you want the labels to be displayed horizontally, then you can add the labels to a panel and then add the panel to your "displayPanel". 如果希望标签水平显示,则可以将标签添加到面板,然后将面板添加到“ displayPanel”。

That is you can nest panels that use different layout managers to get your desired layout. 也就是说,您可以嵌套使用不同布局管理器的面板以获取所需的布局。

Also, use standard Java variable names. 另外,请使用标准Java变量名称。 Variable names should NOT start with an upper case character. 变量名称不应以大写字母开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM