Question

Hey all I am having some trouble trying to get my jlabels to line up the way I want them to. 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.

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. I have no idea how to make this happen and I am completely stumped.. Any help would be appreciated. Thanks!

Was it helpful?

Solution

There is code for the 2 JLabels with ImageIcon inside them and they keep showing up right below each other.

Then is sounds like you are using a 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".

That is you can nest panels that use different layout managers to get your desired layout.

Also, use standard Java variable names. Variable names should NOT start with an upper case character.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top