简体   繁体   English

"JTextfield 不像我想要的那样显示"

[英]The JTextfield doesn't show like I want

I'm new to Java and I can't find a simple solution.我是 Java 新手,找不到简单的解决方案。 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.我想编写一个程序,我可以在其中创建播放列表并保护它们,但由于JTextfield<\/code>太小,我已经一开始就卡住了。

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:您可以通过这种方式为JTextField<\/code>指定大小:

input = new JTextField(20);

When the int in the constructor is to big the JTextField will bug当构造函数中的 int 很大时,JTextField 会出错

I think it's depend of the size of the container.我认为这取决于容器的大小。

here if i write 10 instead of 5 it's doesn't work:在这里,如果我写 10 而不是 5 它不起作用:

Dimension dim = getPreferredSize();
dim.width = 150;
setPreferredSize(dim);
        
nameLabel = new JLabel("Name: ");
nameField = new JTextField(5);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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