Why are my items not showing up in JFrame?

后端 未结 6 1118
日久生厌
日久生厌 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条回答
  •  旧时难觅i
    2020-11-29 11:38

    I agree to MadProgrammer's suggestions (+1)

    Well, lets take a look at your program though

    You actually have created a JFrame with components in it. Its working fine as well, but your question of "why are my items not showing up in the JFrame" is not because you did something wrong but because missed out something i.e. revalidate()

    Try:

    public static void main(String[] args){
            FirstGUI a = new FirstGUI();
            a.GUI();
            a.revalidate();
        }
    

    I'm not saying this will give you perfect UI.. what I'm trying to say is this will help you understand the Swing better. Learn about Swing Layout managers and then work on your UI to have better results

    revalidate(): This component and all parents above it are marked as needing to be laid out. This means the Layout Manager will try to realign the components. Often used after removing components. It is possible that some really sharp swing people may miss this. I would think that you will only know this if you are actually using Swing.

提交回复
热议问题