I'm new to Java and I can't find a simple solution. In the image below, you can see what my problem is. I want to write a program, where I can create playlists and safe them, but I am already stuck at the beginning because the JTextfield<\/code> is too small.
import javax.swing.JFrame;
public class Main {
public static void main(String args[]) {
JFrame w = new Layout();
w.setVisible(true);
w.setSize(600, 600);
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
w.setLocationRelativeTo(null);
w.setResizable(true);
}
}
You can give to the JTextField<\/code> a size in this way:
input = new JTextField(20);
When the int in the constructor is to big the JTextField will bug
I think it's depend of the size of the container.
here if i write 10 instead of 5 it's doesn't work:
Dimension dim = getPreferredSize();
dim.width = 150;
setPreferredSize(dim);
nameLabel = new JLabel("Name: ");
nameField = new JTextField(5);
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.