在调整大小之前,GridBagLayout没有很好地分页

时间:2017-09-27 09:01:47

标签: java swing awt layout-manager gridbaglayout

我是新来的。 我用Java编写了一个简单的程序,并使用GridBagLayout编写了GUI。 问题是,在触摸窗口边框以调整框架大小之前,它没有很好的分页。以下是我的意思的一些照片:

The main window before I resize the frame

The main window after I resize the frame

我的代码的一部分:

public class TW2Tempi
{

    public static void main(String[] args)
    {
        MainFrame mf = new MainFrame();
    }

}

class MainFrame extends JFrame
{
    GridBagConstraints gbc = new GridBagConstraints();
    //other variables .....

    public MainFrame()
    {
        super("Calcola i tempi dei tuoi attacchi");
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new GridBagLayout());
        setPreferredSize(new Dimension(500, 300));
        setMinimumSize(new Dimension(500, 300));
        //setResizable(false); //I would also like to add this but then I wouldn't be able to "resize" and see everything (second picture)

        //row 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //where gbc.gridy = 0

        nobile = new JLabel("Orario di arrivo del nobile", SwingConstants.RIGHT);//right align
        gbc.fill = GridBagConstraints.BOTH;
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 1;
        gbc.insets = new Insets(7,10,0,0);
        gbc.fill = GridBagConstraints.BOTH;
        add(nobile, gbc);
        ....

我是否必须以不同的方式初始化 GridBagConstraints

0 个答案:

没有答案