Why are my items not showing up in JFrame?

后端 未结 6 1128
日久生厌
日久生厌 2020-11-29 10:39

I\'m fairly new to JFrame and I want to know why my items are not showing up on the window. I know i dont have a ActionHandler but I just want my textfield\'s to show up on

6条回答
  •  余生分开走
    2020-11-29 11:43

    Don't add the components directly to your frame. Instead add to the content pane, which is where a JFrame stores all of the components that it draws. Usually this is a JPanel.

    Here is an example:

    public class GUI
    {
    
        private JPanel content;
    
        public void GUI
        {
            /*Other code*/
    
            content = new JPanel();
            add(content); //make content the content pane
    
            content.add(title);
            content.add(login);
            content.add(pass);
        }
    

    If that fails, call setVisible(true) and setEnabled(true) on all of your components.

    On a side note you may want to make your GUI function a constructor.

提交回复
热议问题