Warum geht das JTextField nicht an die Location, die ich eingegeben habe?

Ich möchte einen Login-Screen programmieren. Der Hintergrund ist einfach nur ein JLabel und das E-Mail-Eingabefeld funktioniert. Nur das Passwortfeld nicht. Es wird links am Rand angezeigt. Warum?

package com.utilities.noname.ControlProgram.Window;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JTextField;

import com.utilities.noname.ControlProgram.Window.Label.BoxCordinates;

public class Window {
  JFrame frame;

  Label label;

  int width, height;

  Dimension screenSize;

  boolean login = false;

  public Window() {
    screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    width = (int) (screenSize.getWidth() / 2);
    height = (int) (screenSize.getHeight() / 1.75);

    frame = new JFrame("Control Program");
    frame.setSize(width, height);

    label = new Label(this);
    label.setSize(width, height);
    frame.getContentPane().add(label);
    label.setVisible(true);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);

    loadLogin();

    frame.setVisible(true);
  }

  public void loadLogin() {
    login = true;

    JTextField email = new JTextField();
    email.setBounds(new Rectangle(
      BoxCordinates.emailBoxX + BoxCordinates.stroke,
      BoxCordinates.emailBoxY + BoxCordinates.stroke,
      BoxCordinates.totalWidth - BoxCordinates.stroke * 2,
      BoxCordinates.totalHeight - BoxCordinates.stroke * 2));
    email.setBorder(null);
    email.setBackground(Color.WHITE);

    frame.getContentPane().add(email);
    email.setVisible(true);
    email.requestFocus();

    JTextField password = new JTextField();
    password.setBounds(new Rectangle(
      BoxCordinates.passwordBoxX + BoxCordinates.stroke,
      BoxCordinates.passwordBoxY + BoxCordinates.stroke,
      BoxCordinates.totalWidth - BoxCordinates.stroke * 2,
      BoxCordinates.totalHeight - BoxCordinates.stroke * 2));
    password.setSize(BoxCordinates.totalWidth, BoxCordinates.totalHeight);

    System.out.println("Cords: " + BoxCordinates.passwordBoxX + "," + BoxCordinates.passwordBoxY);

    password.setBorder(null);
    password.setBackground(Color.WHITE);

    frame.getContentPane().add(password);
    password.setVisible(true);
    password.requestFocus();
  }
}
PC, Computer, Handy, Internet, Technik, programmieren, Java, Location, Programmiersprache
1 Antwort