This form is opened by pressing a button. I try to add a textfield component to textfield , but it is not displayed. Tried already for this form methods revalidate() and repaint() , but the component is still not displayed.

 class Better implements ActionListener{ public void actionPerformed (ActionEvent e){ form2.setDefaultCloseOperation(EXIT_ON_CLOSE); form2.setBounds(300,200,600,450); form2.setLayout(null); form2.getContentPane(); form2.add(btn6); form2.add(btn7); form2.add(tf1); tf1.setLocation(200,150); form2.revalidate(); form2.repaint(); btn6.setSize(135,50); btn6.setLocation(450,360); btn7.setSize(134,50); btn7.setLocation(0,360); form1.setVisible(false); form2.setVisible(true); } 

    1 answer 1

    You have not set the size for tf1 , but in general it is better to use the standard set of Layout 's. Their combination for different form objects sure will give you the desired result. Placing objects with absolute positioning is considered a bad programming tone for a rare case. What will you do if before the first button you need to add one more, or add an object that moves the rest of the elements down? Interrupt all constant values?

    • Tell me, can you help me write an interface for the database please? - Slava
    • If the answer helped you, then mark it as correct). And so ask a new question with a specific example of where and what you can’t do. There are many competent people willing to help everyone, but no one will do something for you. - Aleksei Chibisov