如何解决如何更改 JTextField 的大小
我创建了一个 JTextField 并且我使用了无效的 setBounds() 方法。我的代码中没有错误,所以我不确定出了什么问题。我将在下面提供输出的图片和图像。
import java.awt.*;
import javax.swing.*;
public class A1 extends JFrame {
public A1(String title) {
super(title);
this.setSize(500,500);
this.setLocation(100,100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField text1 = new JTextField();
text1.setBounds(50,100,200,30);
Container mainContainer = this.getContentPane();
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setBackground(Color.GRAY);
tabbedPane.setForeground(Color.BLACK);
tabbedPane.setFont(new Font("Century Gothic",Font.BOLD,14));
//tab1
JPanel panel1 = new JPanel();
panel1.setBackground(Color.CYAN);
panel1.add(text1);
//tab2
JPanel panel2 = new JPanel();
tabbedPane.addTab("Future/Present Value",panel1);
tabbedPane.addTab("Financial Ratios",panel2);
mainContainer.add(tabbedPane);
}
public static void main(String[] args) {
A1 launch = new A1("Financial Calculator");
launch.setVisible(true);
}
}
老实说,我很困惑为什么它不改变大小。任何帮助将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。