在调整大小之前,这是我的JFrame:
这是调整大小后的JFrame:
由于调整大小,我只希望JTextArea变大,并保持JFrame的上部大小相同。标签(“ Threads program”)和按钮(“ Press to Start”)都是JPanel中的JPanel。
这是它的构造函数:
public ThreadsGUI()
{
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
lblTitle = new JLabel("Threads program");
cmdStart = new JButton("Press to Start");
txtOutput = new JTextArea(15,0);
lblTitle.setForeground(new Color(0,0,255));
lblTitle.setFont(new Font("Tahoma", 0, 24));
txtOutput.setFont(new Font("Courier New", 0, 20));
cmdStart.setPreferredSize(new Dimension(140,50));
cmdStart.setFont(new Font("Tahoma", 0, 18));
JPanel label = new JPanel();
label.add(lblTitle);
JPanel buttons = new JPanel();
buttons.add(cmdStart);
add(label);
add(buttons);
add(txtOutput);
}