0

I attempted to move the label to a specific location but it failed, anyone have an idea how to fix this?

package Main;

import javax.swing.*;
import java.awt.*;

public class Bread {

    public static void main(String[] args) {
        JFrame B = new JFrame();
        B.setVisible(true);
        B.setSize(800, 600);
        B.setResizable(false);
        B.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        B.setTitle("LolzWut?");
        B.setBackground(Color.WHITE);
        B.setLayout(new FlowLayout());
        JLabel Label = new JLabel("Test");
        Label.setText("Label Text");
        B.add(Label);
        Label.setLocation(200, 300);
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson Dec 20 '13 at 00:22

1 Answers1

3

The JLabel is under the management of a LayoutManager, each time the parent container is revalidated, the JLabel will be positioned to where the LayoutManager wants it.

Take a look at Laying Out Components Within a Container for more details

The question is, why do you think you need to set it's location?

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366