Reputation: 97
I was trying to create form using swing, but the created input field is out of bounds.
My code
package lista_designer_1;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class lista_designer_2 extends JFrame {
JTextField text1;
public static void main(String[] args) {
lista_designer_2 frame1 = new lista_designer_2();
frame1.setSize(450, 300);
frame1.setVisible(true);
}
public lista_designer_2() {
super("Hello World");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
text1 = new JTextField();
text1.setBounds(10, 10, 76, 21);
add(text1);
setVisible(true);
}
}
After running this code it looks like this:
How can i fix it?
Upvotes: 0
Views: 128
Reputation: 636
Try setLayout(null); This will remove the LayoutManager from your JFrame which causes the textfield to appear linke this.
Upvotes: -1
Reputation: 15886
You can use layout managment see A Visual Guide to Layout Managers
For examples see Swing Layout Examples.
Example to use FlowLayout layout:
getContentPane().setLayout(new FlowLayout ());
Upvotes: 2