How do I add a margin outside the border of a component in Swing?

前端 未结 2 1698
不知归路
不知归路 2021-02-20 11:33

I use multiple components that has a border painted. Is there any easy way to add a margin to the component so that the borders aren\'t painted so close to eachother?

2条回答
  •  抹茶落季
    2021-02-20 12:22

    This is typically done using your layout manager. For example, if you are using GridBagLayout, you would set insets on the GridBagConstraint object to the desired value.

    Another option is to use the Box object and add a horizontal or vertical struct. See javadoc for Box.createVerticalStrut( int width ) and the similar createHorizontalStrut.

提交回复
热议问题