简体   繁体   中英

Components won't show up on JFrame

This question is a repeat, but the other answers have not fixed this error. The components I am putting into my JFrame aren't showing up. I have been working with JFrame for a while now and as far as I can tell I am making no mistakes.

My Code:

public void Toutrial_start1()
        {
            Container contentPane = new Container();
            setSize(800,500);
            setLocation(100,100);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setTitle("Wizard101");
            setResizable(false);
            tou1 = new JLabel();
            tou1.setBounds(0,0, 800, 500);
            tou1.setIcon(t1);
            but = new JButton();
            but.setBounds(100,100, 200, 200);
            but.addActionListener(this);
            but.setIcon(t1);
            contentPane.add(but);
            contentPane.add(tou1);
            setVisible(true);
            SchoolDecider();
            genderDecider();
            nameDecider();
            playerStats.Stats();
        }
        @Override
        public void actionPerformed(ActionEvent e)
        {
            // TODO Auto-generated method stub

        }  
    }

you haven't add content yet to the frame.you have created contentPane but haven't add it to jframe .add it before call setVisible()

this.setContentPane(contentPane);
setVisible(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM