Java – the GUI displays elements only after dragging the window
•
Java
frame_ref = new Frame("Login");
frame_ref = new Frame("Login"); mainPanel_ref = new Panel(); buttonPanel_ref = new Panel(); grid_ref = new GridLayout(4,2); frame_ref.setSize(300,120); frame_ref.setVisible(true); email_ref = new TextField(); password_ref = new JPasswordField(); mainPanel_ref.setLayout(grid_ref); mainPanel_ref.add(new Label("E-Mail")); mainPanel_ref.add(email_ref); mainPanel_ref.add(new Label("Passwort")); mainPanel_ref.add(password_ref); mainPanel_ref.add(submitLogin_ref); mainPanel_ref.add(fehlerMeldung_ref); frame_ref.add(mainPanel_ref);
I set up a view in Java above The window is completely empty, but after dragging and dropping its size, all elements are displayed Does anyone know how to solve this problem?
Solution
Call frame_ ref.setVisible(true); In frame_ ref.add(mainPanel_ref); After that
What happens here is that you call frame_ Ref.setvisible (true) display frame; Then add elements to it So you get an empty frame Then, when you drag or resize it, it redraws and you can see the element
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码