How can I set distance between elements ordered vertically?

前端 未结 4 829
孤独总比滥情好
孤独总比滥情好 2021-01-17 13:03

I have code like that:

    JPanel myPanel = new JPanel();
    myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.Y_AXIS));

    JButton button = new JButton(         


        
4条回答
  •  终归单人心
    2021-01-17 13:10

        JPanel myPanel = new JPanel();
        myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.Y_AXIS));
    
        JButton button = new JButton("My Button");
        JLabel label = new JLabel("My label!!!!!!!!!!!");
    
        myPanel.add(button);
        myPanel.add(Box.createVerticalStrut(20));
        myPanel.add(label);
    

    will be one way of doing it.

提交回复
热议问题