当我调整窗口大小时,我的所有面板都会被压缩,并且不会显示所有内容。
这是我的jframe类的代码
import javax.swing.JFrame;
import java.awt.*;
public class CopyText {
public static void main(String[] args) {
JFrame frame = new JFrame("Project 3 Layout");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CopyTextPanel panel = new CopyTextPanel();
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}
这是我的面板安排课程的代码
public class CopyTextPanel extends JPanel {
private JTextField input;
private JLabel output, inlabel, outlabel;
private JButton compute, clear;
private JPanel panel;
public CopyTextPanel() {
inlabel = new JLabel("Input: ");
outlabel = new JLabel("Text Statistics Result: ");
input = new JTextField(50);
output = new JLabel();
compute = new JButton("Compute Statistics");
compute.addActionListener(new ButtonListener());
clear = new JButton("Clear Text");
clear.addActionListener(new ButtonListener());
panel = new JPanel();
//setPreferredSize (new Dimension(700, 150));
output.setPreferredSize(new Dimension(500, 30));
panel.setPreferredSize(new Dimension(620, 100));
panel.setBackground(Color.yellow);
panel.add(inlabel);
panel.add(input);
//panel.add(outlabel);
//panel.add(output);
panel.add(compute);
panel.add(clear);
panel.add(outlabel);
panel.add(output);
setPreferredSize(new Dimension(700, 150));
setBackground(Color.blue);
add(panel);
}
}
ActionEvent课程,因为我觉得这对我想要完成的事情并不重要。另外,当我运行程序时,我的outlabel仍然高于我的输出,但我试图用我的outlabel输出使它成为一行。
谢谢你们!