Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Moin moin, ich habe eine Frage in meiner GUI habe ich ein Problem mit der Grafik. Wenn ich zu viel die GUI bewege verkleinert sich die JTextField ich kann den Fehler leider so nicht finden dazu.

OhneFehler.png.605c7b1a33bccb599096dd4c28d8454d.png

Wenn ich nun die MenuBar öffne passiert folgendes 

 

MitFehler.png.9e9055797e6ce0cbd2d8fe5b7074b581.png

 

Weiß zu fällig jemand, was da verkehrt läuft ? 

 

 

  • Autor
 public DatenbankBewerbungenGUI(Connection connection) {
        this.connection = connection;
        try {
            this.statement = connection.createStatement();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        // GUI initialisieren
        setTitle("Datenbank Bewerbung GUI");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // Größenänderung deaktivieren
        setResizable(false);
        // Erscheinen auf dem Display
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int screenWidth = screenSize.width;
        int screenHeight = screenSize.height;
        int frameWidth = getWidth();
        int frameHeight = getHeight();
        // Anpassung hier Mitte vom Bildschirm starten
        int frameX = (int) ((screenWidth - frameWidth) / 3);
        int frameY = (int) ((screenHeight - frameHeight) / 7);
        setLocation(frameX, frameY);

        // Menüleiste erstellen
        JMenuBar menuBar = new JMenuBar();

        // Menü "File" erstellen
        JMenu fileMenu = new JMenu("File");

        // Menüelement "Exit" erstellen
        JMenuItem exitMenuItem = new JMenuItem("Exit");
        exitMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Hier den Code einfügen, der beim Klicken auf "Exit" ausgeführt werden soll
                System.exit(0);
            }
        }); // Menüelement "Exit" erstellen
        JMenuItem loginMenuItem = new JMenuItem("Login");
        loginMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LoginFrame loginFrame = new LoginFrame();
                loginFrame.setVisible(true);
                           }
        });

        // Menüelemente zum Menü "File" hinzufügen
        fileMenu.add(loginMenuItem);
        fileMenu.add(exitMenuItem);

        // Menü "File" zur Menüleiste hinzufügen
        menuBar.add(fileMenu);

        // Menüleiste zum JFrame hinzufügen
        setJMenuBar(menuBar);

        // GridBagLayout verwenden
        setLayout(new GridBagLayout());

        GridBagConstraints constraints = new GridBagConstraints();
        constraints.insets = new Insets(10, 10, 10, 10); // Abstand zwischen den Komponenten

        lesenButton = new JButton("Tabelle auslesen");
        lesenButton.addActionListener(this);
        constraints.gridx = 0;
        constraints.gridy = 0;
        add(lesenButton, constraints);

        constraints.gridx = 0;
        constraints.gridy = 1;
        add(new JLabel("Name:"), constraints);

        nameField = new JTextField(20);
        constraints.gridx = 1;
        constraints.gridy = 1;
        add(nameField, constraints);

        constraints.gridx = 0;
        constraints.gridy = 2;
        add(new JLabel("Datum:"), constraints);

        datumField = new JTextField(20);
        constraints.gridx = 1;
        constraints.gridy = 2;
        add(datumField, constraints);

        constraints.gridx = 0;
        constraints.gridy = 3;
        add(new JLabel("Adresse:"), constraints);

        adresseField = new JTextField(20);
        constraints.gridx = 1;
        constraints.gridy = 3;
        add(adresseField, constraints);

        abgesagtButton = new JButton("Abgesagt");
        abgesagtButton.addActionListener(this);
        constraints.gridx = 0;
        constraints.gridy = 4;
        add(abgesagtButton, constraints);

        hinzufugenButton = new JButton("Daten hinzufügen");
        hinzufugenButton.addActionListener(this);
        constraints.gridx = 1;
        constraints.gridy = 4;
        add(hinzufugenButton, constraints);

        loschenButton = new JButton("Felder löschen");
        loschenButton.addActionListener(this);
        constraints.gridx = 2;
        constraints.gridy = 4;
        add(loschenButton, constraints);

        datenTabelle = new JTable();
        constraints.gridx = 0;
        constraints.gridy = 5;
        constraints.gridwidth = 3;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.weightx = 1.0;
        constraints.weighty = 1.0;
        add(new JScrollPane(datenTabelle), constraints);

        // Größe des JFrame automatisch anpassen
        pack();
    }

 

vor 2 Stunden schrieb fiedelbambu:
 public DatenbankBewerbungenGUI(Connection connection) {

Das kann niemals der funktionierende Ausschnitt sein. Da fehlt ja die Komplette Vererbung.

Wie soll soll damit der Aufruf der anderen Methoden funktionieren?

z.B.

vor 2 Stunden schrieb fiedelbambu:
 add(new JScrollPane(datenTabelle), constraints);

        // Größe des JFrame automatisch anpassen
        pack();

 

vor 11 Stunden schrieb fiedelbambu:

Das stimmt ich habe einen Teil heraus gelassen. Trotzdessen wurde mir anders wo schon geholfen. Alles gut danke für eure mühen 

Dann wäre es immer schön, wenn du die Lösung hier auch schreibst. So dass andere, die das Problem haben, auch eine Lösung finden.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.