如何使JPanel保持固定大小?

时间:2019-06-04 18:34:52

标签: java swing

在调整大小之前,这是我的JFrame:

enter image description here

这是调整大小后的JFrame:

enter image description here

由于调整大小,我只希望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);
}

0 个答案:

没有答案