关于java swing中GridBagConstraints ipadx和ipady的问题?

1.问题描述

我在一篇教程里看到关于 GridBagConstraints 的ipadx和ipady的描述:

 ipadx, ipady
    Specifies the internal padding: how much to add to the minimum size of  
    the component. The default value is zero. The width of the component  
    will be at least its minimum width plus ipadx*2 pixels, since the  
    padding applies to both sides of the component. Similarly, the height
    of the component will be at least its minimum height plus ipady*2 pixels. 

我理解的大致意思是:
设置ipadx和ipady后得到最终的组件的大小应该是(组件最小宽度+(ipadx or ipady)*2)

举例:
假设 ipadx = 10; ipady = 10; 组件默认宽高是 30 * 40;
按上面的说法就是:最终组件大小是 (30+10*2)*(40+10*2)

出现的疑问

但是在我实际编写案例的时候得到的结果却是:(30+5*2)*(40+5*2)

也就是说,实际上是把ipadx或者ipady平均分配给的组件的上下左右

那么问题就是:是我理解错了还是教程本身在错误,亦或是有其它的理解?

原教程地址:

http://www.math.uni-hamburg.d...
里面有关于ipadx和ipady的描述
谢谢各位了

阅读 4.3k
1 个回答

public int ipadx

   This field specifies the internal padding of the component, how much space to add to the minimum width of the component. The width of the component is at least its minimum width plus ipadx pixels.

   The default value is 0.

   See Also:
       clone(), ipady

ipady

public int ipady

   This field specifies the internal padding, that is, how much space to add to the minimum height of the component. The height of the component is at least its minimum height plus ipady pixels.

   The default value is 0. ```
   
通过查看``javase documents`` 发现并不是``(ipadx or ipady)*2``  而是直接是 ``ipadx or ipady``

###原文档地址:
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题