当前位置: 代码迷 >> 综合 >> gridbaglayout(2)
  详细解决方案

gridbaglayout(2)

热度:16   发布时间:2023-12-13 20:15:37.0

13,"To specify constraints, you set instance variables in a GridBagConstraints object and tell the

GridBagLayout (with the setConstraints method) to associate the constraints with the component."
  要是放在汉语中,可能不怎么容易理解这句话,理解这里面的instance varialbes和setConstraints!!!
14,Specifying Constraints
  !You must be careful, however, to reset the GridBagConstraints instance variables to their default values

when necessary.
     !!gridx, gridy [the position]
        Specify the row and column at the upper left of the component.(以组件的左上为基点来指定此组件的行列.)
          Valid values: 0,GridBagConstraints.RELATIVE( specify that the component be placed just to the right

of (for gridx) or just below (for gridy) the component that was added to the container just before this

component was added.).
          default value:GridBagConstraints.RELATIVE
     !!gridwidth,gridheight [the number of cells]
       specify the number of columns or rows in the component's display area.(what is the component's display

area?)the number of cells the component uses.(也就是说是里面的那些小格子吧?)
        Valid values:GridBagConstraints.REMAINDER or GridBagConstraints.RELATIVE(specify that the component

be the next to last one in its row (for gridwidth) or column (for gridheight).)
           default value: 1
           NOTE:    GridBagLayout doesn't allow components to span multiple rows unless the component is in

the leftmost column or you've specified positive gridx and gridy values for the component.
     !!fill [larger than]
     used when the component's display area is larger then the component's requested size to determine

whether and how resize the component.
       Valid values(as constants):NONE,HORIZONTAL(make the component wide enough to fill its display area but

dont changes its height),VERTICAL(tall enought),and BOTH(fill its display area entirely)
       default value:NONE.
     !!ipadx,ipady (what's the difference between the two and the above gridwidth???????)
       Specifies the internal padding: how much to add to the minimum size of the component.(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.)
       default value:0
     !!insets(??????????????)
       Specifies the external padding of the component -- the minimum amount of space between the component

and the edges of its display area. The value is specified as an Insets object. By default, each component has

no external padding.
     !!anchor [when the component is smaller than its display area to dertermine...]
       Valid values(as GridBagConstraints constants):CENTER (the default), PAGE_START, PAGE_END, LINE_START,

LINE_END, FIRST_LINE_START, FIRST_LINE_END, LAST_LINE_END, and LAST_LINE_START.
     !!weightx, weighty

?????????????????????????????????????????????????????????????????????????????????????????????????????????????

  When you enlarge GridBagLayoutDemo's window, the columns grow proportionately. This is because each

component in the first row, where each component is one column wide, has weightx = 1.0. The actual value of

these components' weightx is unimportant. What matters is that all the components, and consequently, all the

columns, have an equal weight that is greater than 0. If no component managed by the GridBagLayout had

weightx set, then when the components' container was made wider, the components would stay clumped together

in the center of the container.
   ?why is "all the components ,and consequently,all the columns"???