Nicht alle Komponenten werden angezeigt

Status
Nicht offen für weitere Antworten.
G

Guest

Gast
Hallo,

ich versuche mich gerade mit den LayoutManagern.
Ich habe hier ein Formular erstellt, wo ein Benutzer sein Profil beabeiten kann.
Wenn ich das Feld starten möchte, erscheinen leider nicht alle Komponenten, die ich auf das Frame eingefügt habe.
Es erscheinen immer zufällig welche, mal alle, mal 2 mal 3 mal gar keins. Wenn ich das Fenster größer oder kleiner ziehe, sind plötzllich alle Komponenten drauf.

Wie kann ich das Problem lösen?

danke für eure HIlfe


Gruß
 

MarcoBehnke

Bekanntes Mitglied
Dein Code wäre sehr hilfreich, um Dein Problem zu verstehen... sonst wissen wir ja nicht, was Du gemacht hast :D

Welchen LayoutManager benutzt Du?
Wie addest Du die Komponenten etc.... etc....
 
G

Guest

Gast
So hier noch der Code.

Danke für eure Hilfe.

Gruß

Code:
package GUI;

import java.awt.Button;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import Steuerung.Controller;

public class Hauptmenue extends Fenster implements WindowListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5258938663303884198L;
	Panel hauptpanel, formular, buttons;
	Label label0,label1,label2,label3,label4,label5,label6,label7,label8,stern;
	TextField name, vorname,strasse,plz,ort,gebdat,benutzername,pw1,pw2;
	Button save,exit;
	Controller control;
	GridBagLayout gridlayout;
	GridBagConstraints gridcons;
	
			
	public Hauptmenue() {
		super("Hauptmenue", 325, 300, 100, 100, true);
		this.setResizable(false);
		this.setBackground(Color.lightGray);
		// TODO Automatisch erstellter Konstruktoren-Stub
		this.control = new Controller();
		
		gridlayout= new GridBagLayout();
		
		this.setLayout(gridlayout);
		
		this.buttons=new Panel();
		this.label0=new Label();
		this.label1=new Label();
		this.label2=new Label();
		this.label3=new Label();
		this.label4=new Label();
		this.label5=new Label();
		this.label6=new Label();
		this.label7=new Label();
		this.label8=new Label();
		this.stern= new Label();
		this.name=new TextField();
		this.vorname=new TextField();
		this.strasse= new TextField();
		this.plz= new TextField();
		this.ort= new TextField();
		this.gebdat= new TextField();
		this.benutzername= new TextField();
		this.pw1 = new TextField();
		this.pw2= new TextField();
		
		
		
		
		this.bauemenue();
			
		this.addWindowListener(this);
		
		this.save=new Button("Speichern");
		this.exit=new Button("Ende");
		
		this.save.addActionListener(this.control);
		this.exit.addActionListener(this.control);
		
		this.gridcons=this.makegbc(0,0,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label0,this.gridcons);
		this.add(label0);
		
		this.gridcons=this.makegbc(1,0,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.name, this.gridcons);
		add(this.name);
		
		this.gridcons=this.makegbc(2,0, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		
		this.gridcons=this.makegbc(0,1,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label1,this.gridcons);
		this.add(label1);
		
		this.gridcons=this.makegbc(1,1,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.vorname, this.gridcons);
		add(this.vorname);
		
		this.gridcons=this.makegbc(2,1, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,2,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label2,this.gridcons);
		this.add(label2);
		
		this.gridcons=this.makegbc(1,2,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.strasse, this.gridcons);
		add(this.strasse);
		
		this.gridcons=this.makegbc(2,2, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,3,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label3,this.gridcons);
		this.add(label3);
		
		this.gridcons=this.makegbc(1,3,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.plz, this.gridcons);
		add(this.plz);
		
		this.gridcons=this.makegbc(2,3, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		
		this.gridcons=this.makegbc(0,4,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label4,this.gridcons);
		this.add(label4);
		
		this.gridcons=this.makegbc(1,4,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.ort, this.gridcons);
		add(this.ort);
		
		this.gridcons=this.makegbc(2,4, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,5,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label5,this.gridcons);
		this.add(label5);
		
		this.gridcons=this.makegbc(1,5,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.gebdat, this.gridcons);
		add(this.gebdat);
		
		this.gridcons=this.makegbc(2,5, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,6,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label6,this.gridcons);
		this.add(label6);
		
		this.gridcons=this.makegbc(1,6,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.benutzername, this.gridcons);
		add(this.benutzername);
		
		this.gridcons=this.makegbc(2,6, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,7,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label7,this.gridcons);
		this.add(label7);
		
		this.gridcons=this.makegbc(1,7,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.pw1, this.gridcons);
		add(this.pw1);
		
		this.gridcons=this.makegbc(2,7, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,8,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label8,this.gridcons);
		this.add(label8);
		
		this.gridcons=this.makegbc(1,8,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.pw2, this.gridcons);
		add(this.pw2);
		
		this.gridcons=this.makegbc(2,8, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(1, 9, 0, 0);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		this.gridlayout.setConstraints(this.save, this.gridcons);
		this.add(this.save);
		
		this.gridcons=this.makegbc(1, 9, 0, 0);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.NORTH;
		this.gridlayout.setConstraints(this.exit, this.gridcons);
		this.add(this.exit);
		
		
		
		
	}
	
	
	private void bauemenue(){
		
		this.vorname= new TextField();
		this.strasse= new TextField();
		this.plz= new TextField();
		this.ort= new TextField();
		this.gebdat= new TextField();
		this.benutzername= new TextField();
		this.pw1= new TextField();
		this.pw2= new TextField();
		this.pw1.setEchoChar('*');
		this.pw2.setEchoChar('*');
		this.label0.setText("Name:");
		this.label1.setText("Vorname:"); 
		this.label2.setText("Strasse:");
		this.label3.setText("PLZ:");
		this.label4.setText("Ort:");
		this.label5.setText("GebDat:");
		this.label6.setText("Benutzername:");
		this.label7.setText("Passwort:");
		this.label8.setText("PasswortWdh:");
		this.stern.setText("*");
	}
	
	private GridBagConstraints makegbc(int x, int y, int width, int height){
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.gridx=x;
		gbc.gridy=y;
		gbc.gridwidth=width;
		gbc.gridheight=height;
		gbc.insets=new Insets(1,1,1,1);
		return gbc;
	}
	
	public void windowActivated(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

	public void windowClosed(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

	public void windowClosing(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		System.exit(0);
		
	}

	public void windowDeactivated(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

	public void windowDeiconified(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

	public void windowIconified(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

	public void windowOpened(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

}
 
S

SlaterB

Gast
wie schaffst du es eigentlich, das Fenster größer und kleiner zu machen, wenn du
this.setResizable(false);
im Code hast? ;)
außerdem paar unbekannte Klassen und keine main-Operation, toll,

was ist die Fensterklasse, ein Frame oder JFrame?

läuft das hier bei dir?
Code:
public class Hauptmenue
    extends Frame
    implements WindowListener
{

    /**
     * 
     */
    private static final long serialVersionUID = 5258938663303884198L;
    Panel hauptpanel, formular, buttons;
    Label label0, label1, label2, label3, label4, label5, label6, label7, label8, stern;
    TextField name, vorname, strasse, plz, ort, gebdat, benutzername, pw1, pw2;
    Button save, exit;
    GridBagLayout gridlayout;
    GridBagConstraints gridcons;

    public static void main(String[] args)
    {
        new Hauptmenue().setVisible(true);
    }

    public Hauptmenue()
    {
        super("Hauptmenue");
        setSize(400,400);
      //  this.setResizable(false);

        this.setBackground(Color.lightGray);
        // TODO Automatisch erstellter Konstruktoren-Stub


        gridlayout = new GridBagLayout();

        this.setLayout(gridlayout);

        this.buttons = new Panel();
        this.label0 = new Label();
        this.label1 = new Label();
        this.label2 = new Label();
        this.label3 = new Label();
        this.label4 = new Label();
        this.label5 = new Label();
        this.label6 = new Label();
        this.label7 = new Label();
        this.label8 = new Label();
        this.stern = new Label();
        this.name = new TextField();
        this.vorname = new TextField();
        this.strasse = new TextField();
        this.plz = new TextField();
        this.ort = new TextField();
        this.gebdat = new TextField();
        this.benutzername = new TextField();
        this.pw1 = new TextField();
        this.pw2 = new TextField();


        this.bauemenue();

        this.addWindowListener(this);

        this.save = new Button("Speichern");
        this.exit = new Button("Ende");


        this.gridcons = this.makegbc(0, 0, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.WEST;
        gridlayout.setConstraints(label0, this.gridcons);
        this.add(label0);

        this.gridcons = this.makegbc(1, 0, 1, 1);
        this.gridcons.weightx = 100;
        this.gridcons.fill = GridBagConstraints.HORIZONTAL;
        this.gridlayout.setConstraints(this.name, this.gridcons);
        add(this.name);

        this.gridcons = this.makegbc(2, 0, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.stern = new Label();
        this.stern.setText("*");
        this.gridlayout.setConstraints(this.stern, this.gridcons);
        add(this.stern);


        this.gridcons = this.makegbc(0, 1, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.WEST;
        gridlayout.setConstraints(label1, this.gridcons);
        this.add(label1);

        this.gridcons = this.makegbc(1, 1, 1, 1);
        this.gridcons.weightx = 100;
        this.gridcons.fill = GridBagConstraints.HORIZONTAL;
        this.gridlayout.setConstraints(this.vorname, this.gridcons);
        add(this.vorname);

        this.gridcons = this.makegbc(2, 1, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.stern = new Label();
        this.stern.setText("*");
        this.gridlayout.setConstraints(this.stern, this.gridcons);
        add(this.stern);

        this.gridcons = this.makegbc(0, 2, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.WEST;
        gridlayout.setConstraints(label2, this.gridcons);
        this.add(label2);

        this.gridcons = this.makegbc(1, 2, 1, 1);
        this.gridcons.weightx = 100;
        this.gridcons.fill = GridBagConstraints.HORIZONTAL;
        this.gridlayout.setConstraints(this.strasse, this.gridcons);
        add(this.strasse);

        this.gridcons = this.makegbc(2, 2, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.stern = new Label();
        this.stern.setText("*");
        this.gridlayout.setConstraints(this.stern, this.gridcons);
        add(this.stern);

        this.gridcons = this.makegbc(0, 3, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.WEST;
        gridlayout.setConstraints(label3, this.gridcons);
        this.add(label3);

        this.gridcons = this.makegbc(1, 3, 1, 1);
        this.gridcons.weightx = 100;
        this.gridcons.fill = GridBagConstraints.HORIZONTAL;
        this.gridlayout.setConstraints(this.plz, this.gridcons);
        add(this.plz);

        this.gridcons = this.makegbc(2, 3, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.stern = new Label();
        this.stern.setText("*");
        this.gridlayout.setConstraints(this.stern, this.gridcons);
        add(this.stern);


        this.gridcons = this.makegbc(0, 4, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.WEST;
        gridlayout.setConstraints(label4, this.gridcons);
        this.add(label4);

        this.gridcons = this.makegbc(1, 4, 1, 1);
        this.gridcons.weightx = 100;
        this.gridcons.fill = GridBagConstraints.HORIZONTAL;
        this.gridlayout.setConstraints(this.ort, this.gridcons);
        add(this.ort);

        this.gridcons = this.makegbc(2, 4, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.stern = new Label();
        this.stern.setText("*");
        this.gridlayout.setConstraints(this.stern, this.gridcons);
        add(this.stern);

        this.gridcons = this.makegbc(0, 5, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.WEST;
        gridlayout.setConstraints(label5, this.gridcons);
        this.add(label5);

        this.gridcons = this.makegbc(1, 5, 1, 1);
        this.gridcons.weightx = 100;
        this.gridcons.fill = GridBagConstraints.HORIZONTAL;
        this.gridlayout.setConstraints(this.gebdat, this.gridcons);
        add(this.gebdat);

        this.gridcons = this.makegbc(2, 5, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.stern = new Label();
        this.stern.setText("*");
        this.gridlayout.setConstraints(this.stern, this.gridcons);
        add(this.stern);

        this.gridcons = this.makegbc(0, 6, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.WEST;
        gridlayout.setConstraints(label6, this.gridcons);
        this.add(label6);

        this.gridcons = this.makegbc(1, 6, 1, 1);
        this.gridcons.weightx = 100;
        this.gridcons.fill = GridBagConstraints.HORIZONTAL;
        this.gridlayout.setConstraints(this.benutzername, this.gridcons);
        add(this.benutzername);

        this.gridcons = this.makegbc(2, 6, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.stern = new Label();
        this.stern.setText("*");
        this.gridlayout.setConstraints(this.stern, this.gridcons);
        add(this.stern);

        this.gridcons = this.makegbc(0, 7, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.WEST;
        gridlayout.setConstraints(label7, this.gridcons);
        this.add(label7);

        this.gridcons = this.makegbc(1, 7, 1, 1);
        this.gridcons.weightx = 100;
        this.gridcons.fill = GridBagConstraints.HORIZONTAL;
        this.gridlayout.setConstraints(this.pw1, this.gridcons);
        add(this.pw1);

        this.gridcons = this.makegbc(2, 7, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.stern = new Label();
        this.stern.setText("*");
        this.gridlayout.setConstraints(this.stern, this.gridcons);
        add(this.stern);

        this.gridcons = this.makegbc(0, 8, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.WEST;
        gridlayout.setConstraints(label8, this.gridcons);
        this.add(label8);

        this.gridcons = this.makegbc(1, 8, 1, 1);
        this.gridcons.weightx = 100;
        this.gridcons.fill = GridBagConstraints.HORIZONTAL;
        this.gridlayout.setConstraints(this.pw2, this.gridcons);
        add(this.pw2);

        this.gridcons = this.makegbc(2, 8, 1, 1);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.stern = new Label();
        this.stern.setText("*");
        this.gridlayout.setConstraints(this.stern, this.gridcons);
        add(this.stern);

        this.gridcons = this.makegbc(1, 9, 0, 0);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.WEST;
        this.gridlayout.setConstraints(this.save, this.gridcons);
        this.add(this.save);

        this.gridcons = this.makegbc(1, 9, 0, 0);
        this.gridcons.fill = GridBagConstraints.NONE;
        this.gridcons.anchor = GridBagConstraints.NORTH;
        this.gridlayout.setConstraints(this.exit, this.gridcons);
        this.add(this.exit);


    }


    private void bauemenue()
    {

        this.vorname = new TextField();
        this.strasse = new TextField();
        this.plz = new TextField();
        this.ort = new TextField();
        this.gebdat = new TextField();
        this.benutzername = new TextField();
        this.pw1 = new TextField();
        this.pw2 = new TextField();
        this.pw1.setEchoChar('*');
        this.pw2.setEchoChar('*');
        this.label0.setText("Name:");
        this.label1.setText("Vorname:");
        this.label2.setText("Strasse:");
        this.label3.setText("PLZ:");
        this.label4.setText("Ort:");
        this.label5.setText("GebDat:");
        this.label6.setText("Benutzername:");
        this.label7.setText("Passwort:");
        this.label8.setText("PasswortWdh:");
        this.stern.setText("*");
    }

    private GridBagConstraints makegbc(int x, int y, int width, int height)
    {
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = x;
        gbc.gridy = y;
        gbc.gridwidth = width;
        gbc.gridheight = height;
        gbc.insets = new Insets(1, 1, 1, 1);
        return gbc;
    }

    public void windowActivated(WindowEvent arg0)
    {
        // TODO Automatisch erstellter Methoden-Stub

    }

    public void windowClosed(WindowEvent arg0)
    {
        // TODO Automatisch erstellter Methoden-Stub

    }

    public void windowClosing(WindowEvent arg0)
    {
        // TODO Automatisch erstellter Methoden-Stub
        System.exit(0);

    }

    public void windowDeactivated(WindowEvent arg0)
    {
        // TODO Automatisch erstellter Methoden-Stub

    }

    public void windowDeiconified(WindowEvent arg0)
    {
        // TODO Automatisch erstellter Methoden-Stub

    }

    public void windowIconified(WindowEvent arg0)
    {
        // TODO Automatisch erstellter Methoden-Stub

    }

    public void windowOpened(WindowEvent arg0)
    {
        // TODO Automatisch erstellter Methoden-Stub

    }

}
 

Marco13

Top Contributor
Weiteres häufiges Problem: Die Component wird zu früh sichtbar gemacht.
setVisible(true)
sollte als LETZTES ausgefürt werden, NACHDEM alle Components geaddet wurden.
 
G

Guest

Gast
So hier ist der Rest vom Schützenfest.
Wie Du siehst benutze ich Frame und kein JFrame.
Ich weiß das ich nich resizen kann, aber wenn ich es mache, funktioniert es ja, sobald ich die Größe des Fensters veränder.

Habt ihr jetzt einen Rat??

Gruß




Code:
package GUI;

import java.awt.Button;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import Steuerung.Controller;

public class Hauptmenue extends Fenster implements WindowListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5258938663303884198L;
	Panel hauptpanel, formular, buttons;
	Label label0,label1,label2,label3,label4,label5,label6,label7,label8,stern;
	TextField name, vorname,strasse,plz,ort,gebdat,benutzername,pw1,pw2;
	Button save,exit;
	Controller control;
	GridBagLayout gridlayout;
	GridBagConstraints gridcons;
	
			
	public Hauptmenue() {
		super("Hauptmenue", 325, 300, 100, 100, true);
		this.setResizable(false);
		this.setBackground(Color.lightGray);
		// TODO Automatisch erstellter Konstruktoren-Stub
		this.control = new Controller();
		
		gridlayout= new GridBagLayout();
		
		this.setLayout(gridlayout);
		
		this.buttons=new Panel();
		this.label0=new Label();
		this.label1=new Label();
		this.label2=new Label();
		this.label3=new Label();
		this.label4=new Label();
		this.label5=new Label();
		this.label6=new Label();
		this.label7=new Label();
		this.label8=new Label();
		this.stern= new Label();
		this.name=new TextField();
		this.vorname=new TextField();
		this.strasse= new TextField();
		this.plz= new TextField();
		this.ort= new TextField();
		this.gebdat= new TextField();
		this.benutzername= new TextField();
		this.pw1 = new TextField();
		this.pw2= new TextField();
		
		
		
		
		this.bauemenue();
			
		this.addWindowListener(this);
		
		this.save=new Button("Speichern");
		this.exit=new Button("Ende");
		
		this.save.addActionListener(this.control);
		this.exit.addActionListener(this.control);
		
		this.gridcons=this.makegbc(0,0,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label0,this.gridcons);
		this.add(label0);
		
		this.gridcons=this.makegbc(1,0,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.name, this.gridcons);
		add(this.name);
		
		this.gridcons=this.makegbc(2,0, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		
		this.gridcons=this.makegbc(0,1,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label1,this.gridcons);
		this.add(label1);
		
		this.gridcons=this.makegbc(1,1,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.vorname, this.gridcons);
		add(this.vorname);
		
		this.gridcons=this.makegbc(2,1, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,2,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label2,this.gridcons);
		this.add(label2);
		
		this.gridcons=this.makegbc(1,2,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.strasse, this.gridcons);
		add(this.strasse);
		
		this.gridcons=this.makegbc(2,2, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,3,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label3,this.gridcons);
		this.add(label3);
		
		this.gridcons=this.makegbc(1,3,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.plz, this.gridcons);
		add(this.plz);
		
		this.gridcons=this.makegbc(2,3, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		
		this.gridcons=this.makegbc(0,4,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label4,this.gridcons);
		this.add(label4);
		
		this.gridcons=this.makegbc(1,4,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.ort, this.gridcons);
		add(this.ort);
		
		this.gridcons=this.makegbc(2,4, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,5,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label5,this.gridcons);
		this.add(label5);
		
		this.gridcons=this.makegbc(1,5,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.gebdat, this.gridcons);
		add(this.gebdat);
		
		this.gridcons=this.makegbc(2,5, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,6,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label6,this.gridcons);
		this.add(label6);
		
		this.gridcons=this.makegbc(1,6,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.benutzername, this.gridcons);
		add(this.benutzername);
		
		this.gridcons=this.makegbc(2,6, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,7,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label7,this.gridcons);
		this.add(label7);
		
		this.gridcons=this.makegbc(1,7,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.pw1, this.gridcons);
		add(this.pw1);
		
		this.gridcons=this.makegbc(2,7, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(0,8,1,1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		gridlayout.setConstraints(label8,this.gridcons);
		this.add(label8);
		
		this.gridcons=this.makegbc(1,8,1,1);
		this.gridcons.weightx=100;
		this.gridcons.fill=GridBagConstraints.HORIZONTAL;
		this.gridlayout.setConstraints(this.pw2, this.gridcons);
		add(this.pw2);
		
		this.gridcons=this.makegbc(2,8, 1, 1);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.stern=new Label();
		this.stern.setText("*");
		this.gridlayout.setConstraints(this.stern, this.gridcons);
		add(this.stern);
		
		this.gridcons=this.makegbc(1, 9, 0, 0);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.WEST;
		this.gridlayout.setConstraints(this.save, this.gridcons);
		this.add(this.save);
		
		this.gridcons=this.makegbc(1, 9, 0, 0);
		this.gridcons.fill=GridBagConstraints.NONE;
		this.gridcons.anchor=GridBagConstraints.NORTH;
		this.gridlayout.setConstraints(this.exit, this.gridcons);
		this.add(this.exit);
		
		
		
		
	}
	
	
	private void bauemenue(){
		
		this.vorname= new TextField();
		this.strasse= new TextField();
		this.plz= new TextField();
		this.ort= new TextField();
		this.gebdat= new TextField();
		this.benutzername= new TextField();
		this.pw1= new TextField();
		this.pw2= new TextField();
		this.pw1.setEchoChar('*');
		this.pw2.setEchoChar('*');
		this.label0.setText("Name:");
		this.label1.setText("Vorname:"); 
		this.label2.setText("Strasse:");
		this.label3.setText("PLZ:");
		this.label4.setText("Ort:");
		this.label5.setText("GebDat:");
		this.label6.setText("Benutzername:");
		this.label7.setText("Passwort:");
		this.label8.setText("PasswortWdh:");
		this.stern.setText("*");
	}
	
	private GridBagConstraints makegbc(int x, int y, int width, int height){
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.gridx=x;
		gbc.gridy=y;
		gbc.gridwidth=width;
		gbc.gridheight=height;
		gbc.insets=new Insets(1,1,1,1);
		return gbc;
	}
	
	public void windowActivated(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

	public void windowClosed(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

	public void windowClosing(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		System.exit(0);
		
	}

	public void windowDeactivated(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

	public void windowDeiconified(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

	public void windowIconified(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

	public void windowOpened(WindowEvent arg0) {
		// TODO Automatisch erstellter Methoden-Stub
		
	}

}
Code:
package GUI;

import java.awt.Frame;

public class Fenster extends Frame{
	
	
	
	public Fenster(String name, int x, int y, int posx, int posy, boolean visible){
		this.setTitle(name);
		this.setSize(x,y);
		this.setLocation(posx, posy);
		this.setVisible(visible);
	}

	

	

	

}
Code:
package Main;

import GUI.Hauptmenue;

public class Start {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Automatisch erstellter Methoden-Stub
		Hauptmenue menue = new Hauptmenue();

	}

}
 
G

Guest

Gast
Funktioniert jetzt. Ich habe setVisible(true) ganz ans Ende gesetzt, danke für deine HIlfe.


Gruß
 
S

SlaterB

Gast
bei mir zumindest keine Probleme

edit: oh,ja, das mit dem setVisible kann gut sein, dass hatte ich in meiner main ;)
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
R removeAll() beseitigt nicht alle Komponenten!? AWT, Swing, JavaFX & SWT 11
Davee JavaFX JavaFX Jar ausführbar jedoch nicht alle Stages AWT, Swing, JavaFX & SWT 3
F JFrame zeigt nicht alle Elemente auf anhieb an AWT, Swing, JavaFX & SWT 4
B Swing JButton deaktivieren, wenn nicht alle JTextFields ausgefüllt sind. AWT, Swing, JavaFX & SWT 2
D Funktion JList.getSelectedValues() gibt nicht alle values zurück AWT, Swing, JavaFX & SWT 2
F Nicht alle Bilder werden angezeigt AWT, Swing, JavaFX & SWT 2
K Graphics-Objekt zeichnet nicht alle Bilder AWT, Swing, JavaFX & SWT 3
M JList zeigt nicht alle Elemente AWT, Swing, JavaFX & SWT 4
Juelin Text und Backgroundcolor im Label geht nicht AWT, Swing, JavaFX & SWT 7
richis-fragen Spaltenbreite bei drag nicht änderbar AWT, Swing, JavaFX & SWT 4
Juelin if Abfrage funktioniert nicht richtig AWT, Swing, JavaFX & SWT 10
MiMa Darstellung von FXML ateien nicht korrekt (SceneBuilder) AWT, Swing, JavaFX & SWT 2
P Methode wird nicht überprüft AWT, Swing, JavaFX & SWT 4
C Button ActionListener funktioniert nicht AWT, Swing, JavaFX & SWT 1
M Mandelbrot mit BigDecimal erstellen und in der UI zeichnen, funktionierte nicht. AWT, Swing, JavaFX & SWT 1
H JavaFX PixelWriter.setColor setzt Farbe nicht AWT, Swing, JavaFX & SWT 2
M JavaFX Diagonale Linie nicht ausgegeben/angezeigt AWT, Swing, JavaFX & SWT 1
M JavaFX Mandelbrot-bild noch nicht optimiert AWT, Swing, JavaFX & SWT 7
Hatsi09 Javafx MediaPlayer spielt nicht immer AWT, Swing, JavaFX & SWT 3
P thread nimmt veränderte boolean nicht AWT, Swing, JavaFX & SWT 7
P Animation läuft nicht korrekt AWT, Swing, JavaFX & SWT 8
P AWT Programm funktioniert nicht richtig AWT, Swing, JavaFX & SWT 35
P JTextField wird nur sehr klein angezeigt und verändert die Größe nicht AWT, Swing, JavaFX & SWT 3
Telisti Javafx Image wird nicht richtig integiert AWT, Swing, JavaFX & SWT 8
J Netbeans die JavaFX-Anwendung wird nicht ausgeführt AWT, Swing, JavaFX & SWT 16
thor_norsk Icons laden nicht in GUI AWT, Swing, JavaFX & SWT 15
N €-Zeichen wird nicht akzeptiert AWT, Swing, JavaFX & SWT 4
tommybalbor JavaFx Anwendung klappt nicht für macOs Nutzern, wenn ich zwei dependecies bei maven hinzufüge AWT, Swing, JavaFX & SWT 6
G JOptionPane zeigt nicht an was ich will AWT, Swing, JavaFX & SWT 2
S JavaFX WebView zeigt bestimmte Websites nicht an AWT, Swing, JavaFX & SWT 2
R auto. Importanweisungen für javafx funktioniert in Eclipse nicht mehr AWT, Swing, JavaFX & SWT 4
berserkerdq2 Anchorpane warum kann ich nicht Anchors setzen AWT, Swing, JavaFX & SWT 6
komplettlost Vollbildmodus für MacOs Nutzer geht nicht AWT, Swing, JavaFX & SWT 13
M Scrollbar funktioniert nicht AWT, Swing, JavaFX & SWT 10
D Repaint Funktioniert nicht AWT, Swing, JavaFX & SWT 2
W JEditorPane textausrichtung nach settext funktioniert nicht mehr AWT, Swing, JavaFX & SWT 11
H JList.setEnabled(false) - Text soll nicht grau sein AWT, Swing, JavaFX & SWT 2
_user_q Objekt.setSelected(false), wenn es nicht mehr fokussiert wird AWT, Swing, JavaFX & SWT 2
sserio JFrame setIconImmage() funktioniert nicht AWT, Swing, JavaFX & SWT 3
R Fxml findet controller nicht AWT, Swing, JavaFX & SWT 2
D Swing Komponenten nicht sichtbar nach Start AWT, Swing, JavaFX & SWT 12
frager2345 Warum paintComponent hier und nicht paint AWT, Swing, JavaFX & SWT 2
_user_q [JavaFX] Spinner so einstellen, dass er nicht leer bleiben darf? AWT, Swing, JavaFX & SWT 6
T Swing Tooltip-Delay funktioniert nicht immer. AWT, Swing, JavaFX & SWT 1
J Programm findet Resource nicht. AWT, Swing, JavaFX & SWT 6
S Javafx getResource-Pfad wird nicht erkannt AWT, Swing, JavaFX & SWT 7
B Swing Menü geht nicht AWT, Swing, JavaFX & SWT 5
B Bild lädt nicht AWT, Swing, JavaFX & SWT 2
princess_sara1997 .jar Datei führt den Code nicht richtig aus AWT, Swing, JavaFX & SWT 19
S Ich bringe Code mit JavaFX unter Apache NetBeans IDE 12.6 nicht zum laufen. AWT, Swing, JavaFX & SWT 14
U Code doch nicht austauschbar in 2DGraphics AWT, Swing, JavaFX & SWT 2
P JavaFX Änderungen am Datenmodell visuell nicht sichtbar AWT, Swing, JavaFX & SWT 3
M JavaFX kann man da noch was am code vereinfachen design technisch sieht nicht richtig aus... AWT, Swing, JavaFX & SWT 15
S ChoiceBox aus ArrayList per setValue() mit Wert belegen funktioniert nicht. AWT, Swing, JavaFX & SWT 0
ProggersWorld JavaFX TextArea BackgroundImage wird nicht angezeigt AWT, Swing, JavaFX & SWT 3
K Textarea aktuallisiert sich nicht, nach Auswahl (Itemlistener) AWT, Swing, JavaFX & SWT 3
G JavaFX Scene ausdrucken nicht möglich, Seite leer AWT, Swing, JavaFX & SWT 5
N Programm Läuft nicht auf anderen Pcs AWT, Swing, JavaFX & SWT 9
izoards Bild ausdrucken - PageFormat setzen geht nicht AWT, Swing, JavaFX & SWT 5
H KeyListener funktioniert nicht AWT, Swing, JavaFX & SWT 1
B Swing JScrollPane scrollt nicht AWT, Swing, JavaFX & SWT 10
H BufferedImage zurücksetzen funktioniert nicht AWT, Swing, JavaFX & SWT 12
H RPG Programmieren, label.setLocation funktioniert nicht AWT, Swing, JavaFX & SWT 7
S e(fx)clipse erscheint nicht im Marketplace, lässt sich nicht installieren AWT, Swing, JavaFX & SWT 16
M Bild wird nicht geladen obwohl sie gefunden wird AWT, Swing, JavaFX & SWT 0
M Nach Export als Runnable Jar wird css nicht merh gefunden AWT, Swing, JavaFX & SWT 22
L JavaFX .fxml laden klappt nicht AWT, Swing, JavaFX & SWT 16
izoards Outlook Mail erstellen - Signatur wird nicht angezeigt. AWT, Swing, JavaFX & SWT 3
melaniemueller JavaFX Beispiel kann nicht ausgeführt werden AWT, Swing, JavaFX & SWT 4
EinNickname9 Einfacher parser funktioniert nicht AWT, Swing, JavaFX & SWT 2
P Checkboxes in JTable nicht editable AWT, Swing, JavaFX & SWT 9
2 JavaFX die ChoiceBox leitet den String nicht weiter oder es komm zu einem NullPointer AWT, Swing, JavaFX & SWT 8
J actionperformed wird nicht aufgerufen/ repaint() AWT, Swing, JavaFX & SWT 6
G Gui updated beim zweiten Aufruf nicht mehr AWT, Swing, JavaFX & SWT 15
J Java FX NullPointerException, ObservableList wird in View nicht angezeigt.. AWT, Swing, JavaFX & SWT 34
F Swing Adapt Row Height funktioniert nicht richtig :( AWT, Swing, JavaFX & SWT 7
Kotelettklopfer Frame ändert Farbe nicht AWT, Swing, JavaFX & SWT 12
DeBoiJoshua 2D-Grafik Gif Animation will nicht laden AWT, Swing, JavaFX & SWT 1
A TableView updatet sich nicht AWT, Swing, JavaFX & SWT 3
S Next_Button wird nicht ausgeführt. AWT, Swing, JavaFX & SWT 6
P Swing jxmapviewer hinzufügen/nutzen funktioniert nicht AWT, Swing, JavaFX & SWT 7
G JavaFX , Duplicate erzeugt aber ich weis nicht wo AWT, Swing, JavaFX & SWT 4
FrittenFritze Ein Problem mit der CSSBox, die Größe wird nicht angepasst AWT, Swing, JavaFX & SWT 5
B Mit ContentPane werden Komponenten angezeigt, mit SplitPane, JPanel nicht? AWT, Swing, JavaFX & SWT 6
I AWT java.awt.FileDialog - "coffee cup"-Icon lässt sich nicht ersetzen AWT, Swing, JavaFX & SWT 14
CptK windowClosed() nur aufrufen, wenn Fenster nicht über Button geschlossen wird AWT, Swing, JavaFX & SWT 1
H maxWidth greift nicht AWT, Swing, JavaFX & SWT 15
J Swing Werte des JTable werden nicht angezeigt AWT, Swing, JavaFX & SWT 9
J Swing JList wird nicht angezeigt AWT, Swing, JavaFX & SWT 6
J Anbindung Textfeldklasse an Table funktioniert nicht AWT, Swing, JavaFX & SWT 3
beli3ver JavaFX Anwendung startet nicht, kann den Fehler nicht finden (Exception in Application start method) AWT, Swing, JavaFX & SWT 1
T Swing JTable cellRenderer mit jpg Hintergrundfarbe lässt sich nicht ändern. AWT, Swing, JavaFX & SWT 1
T Gui öffnet nicht AWT, Swing, JavaFX & SWT 2
JojoSand Java Programm wird nicht gestartet - keinen Fehlerhinweis AWT, Swing, JavaFX & SWT 9
R Actionlistener funktioniert nicht AWT, Swing, JavaFX & SWT 4
HoT Sortieren von ein paar Zeilen in einer Tabelle, aber nicht die ganze Tabelle AWT, Swing, JavaFX & SWT 3
R JOptionPane schließt sich nicht wieder AWT, Swing, JavaFX & SWT 2
R Textfield lässt sich nicht positionieren AWT, Swing, JavaFX & SWT 1
H JButtons werden nicht angezeigt AWT, Swing, JavaFX & SWT 5
R Text vom Jlabel wird nicht angezeigt AWT, Swing, JavaFX & SWT 2

Ähnliche Java Themen

Neue Themen


Oben