There are 3 classes, PanelEntryWindow is called in FrameEntryWindow, in turn FrameEntryWindow is called in Entry Window, and EntryWindow in Main. The problem is the following - when you start the program, the panel with buttons, text fields and labels is not displayed.

Main

import View.EntryWindow; public class Main { public static void main(String[] args) { EntryWindow.startEntryWindow(); } } 

EntryWindow

 package View; import javax.swing.*; public class EntryWindow extends JFrame { public static void startEntryWindow(){ FrameEntryWindow.FrameEntryWindow(); } } 

FrameEntryWindow

 package View; import javax.swing.*; public class FrameEntryWindow extends JFrame { protected static JFrame jFrame = new FrameEntryWindow(); static JFrame FrameEntryWindow(){ jFrame = new JFrame("My Data Base"); jFrame.setSize(250, 350); jFrame.setLocationRelativeTo(null); jFrame.setResizable(false); jFrame.setVisible(true); jFrame.add(new PanelEntryWindow()); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); return jFrame; } } 

PanelEntryWindow

 package View; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class PanelEntryWindow extends JPanel { private JLabel labelLogin = new JLabel("Login"); public JTextField inputLogin = new JTextField(); private JLabel labelPassword = new JLabel("Password"); public JTextField inputPassword = new JTextField(); public static JButton logInButton = new JButton("Login"); public static JButton newUserButton = new JButton("Create new user"); public PanelEntryWindow(){ labelLogin.setBounds(50, 50, 100, 50); add(labelLogin); inputLogin.setBounds(50, 110, 150, 50); add(inputLogin); labelPassword.setBounds(50, 130, 100, 50); add(labelLogin); inputPassword.setBounds(50, 190, 150, 50); add(inputPassword); logInButton.setBounds(100, 230, 80, 50); add(logInButton); newUserButton.setBounds(50, 290, 200, 50); add(newUserButton); } } 

The structure is as follows:

enter image description here

    1 answer 1

    The problem is in adjusting the size for the panel. If you set the main window resizable to true in the code and stretch the window, you will see your panel. The solution here is simple - do not set the window size manually, but use the pack () method.

    • Thanks for the help - Ilya
    • Could you do something to set your window size? Or will it always be necessary to set the coordinates in setBounds ()? - Ilya
    • @ Ilya setSize method (int, int) if you are talking about it. - Ladence
    • I mean that when in the Frame I add the pack () method at the end, it makes the window exactly the same size so that all the elements fit, making the window small. I would like to leave the distance from the edges of the window to the elements, if I first set the setSize () method, and below pack (), there will be the same result as if there is no setSize () method. The question is how to make a window of a certain size and to display the elements? - Ilya
    • @ Ilya manually adjust the size of the window and use the layouts. docs.oracle.com/javase/tutorial/uiswing/layout/visual.html - Ladence