@@ -161,43 +161,49 @@ public static Container encloseIn(int columns, Component... cmp) {
161
161
private boolean isLandscapeMode () {
162
162
return landscapeRows > -1 && (!Display .getInstance ().isPortrait ());
163
163
}
164
-
165
- private void autoSizeCols (Container parent , int width , boolean landscapeMode ) {
164
+
165
+ private int autoSizeCols (Container parent , int width , boolean landscapeMode ) {
166
+ int numOfcomponents = parent .getComponentCount ();
167
+ int totalComponentCount = numOfcomponents ;
166
168
if (isAutoFit ()) {
167
- int numOfcomponents = parent .getComponentCount ();
168
169
int maxWidth = 0 ;
169
170
for (int iter = 0 ; iter < numOfcomponents ; iter ++) {
170
171
Component cmp = parent .getComponentAt (iter );
171
- Style s = cmp .getStyle ();
172
- maxWidth = Math .max (cmp .getPreferredW () + s .getHorizontalMargins (), maxWidth );
172
+ if (hideZeroSized && cmp .isHidden ()) {
173
+ totalComponentCount --;
174
+ } else {
175
+ Style s = cmp .getStyle ();
176
+ maxWidth = Math .max (cmp .getPreferredW () + s .getHorizontalMargins (), maxWidth );
177
+ }
173
178
}
174
179
if (width < maxWidth ) {
175
180
width = Display .getInstance ().getDisplayWidth ();
176
181
}
177
182
if (landscapeMode ) {
178
- // prevent arithmentic exception
183
+ // prevent arithmetic exception
179
184
if (maxWidth <= 0 ) {
180
185
landscapeColumns = 1 ;
181
186
} else {
182
187
landscapeColumns = Math .max (width / maxWidth , 1 );
183
188
}
184
- landscapeRows = Math .max (1 , numOfcomponents / landscapeColumns );
185
- if (numOfcomponents % landscapeColumns > 0 && numOfcomponents > landscapeColumns ) {
189
+ landscapeRows = Math .max (1 , totalComponentCount / landscapeColumns );
190
+ if (totalComponentCount % landscapeColumns > 0 && totalComponentCount > landscapeColumns ) {
186
191
landscapeRows ++;
187
- }
192
+ }
188
193
} else {
189
194
// prevent arithmentic exception
190
195
if (maxWidth <= 0 ) {
191
196
portraitColumns = 1 ;
192
197
} else {
193
198
portraitColumns = Math .max (width / maxWidth , 1 );
194
199
}
195
- portraitRows = Math .max (1 , numOfcomponents / portraitColumns );
196
- if (numOfcomponents % portraitColumns > 0 && numOfcomponents > portraitColumns ) {
200
+ portraitRows = Math .max (1 , totalComponentCount / portraitColumns );
201
+ if (totalComponentCount % portraitColumns > 0 && totalComponentCount > portraitColumns ) {
197
202
portraitRows ++;
198
- }
203
+ }
199
204
}
200
205
}
206
+ return totalComponentCount ;
201
207
}
202
208
203
209
/**
@@ -276,11 +282,11 @@ public void layoutContainer(Container parent) {
276
282
277
283
/**
278
284
* {@inheritDoc}
279
- */
280
- public Dimension getPreferredSize (Container parent ) {
285
+ */
286
+ public Dimension getPreferredSize (Container parent ) {
281
287
int width = 0 ;
282
288
int height = 0 ;
283
-
289
+
284
290
int numOfcomponents = parent .getComponentCount ();
285
291
int totalComponentCount = numOfcomponents ;
286
292
for (int i =0 ; i < numOfcomponents ; i ++){
@@ -293,7 +299,7 @@ public Dimension getPreferredSize(Container parent) {
293
299
}
294
300
}
295
301
296
- boolean landscapeMode = isLandscapeMode ();
302
+ boolean landscapeMode = isLandscapeMode ();
297
303
autoSizeCols (parent , parent .getWidth (), landscapeMode );
298
304
int rows , columns ;
299
305
if (landscapeMode ) {
@@ -307,18 +313,18 @@ public Dimension getPreferredSize(Container parent) {
307
313
if (columns > 1 ){
308
314
width = width *columns ;
309
315
}
310
-
316
+
311
317
if (rows > 1 ){
312
318
if (totalComponentCount >rows *columns ){ //if there are more components than planned
313
- height = height * (totalComponentCount /columns + (totalComponentCount %columns == 0 ? 0 : 1 ));
319
+ height = height * (totalComponentCount /columns + (totalComponentCount %columns == 0 ? 0 : 1 ));
314
320
}else {
315
321
height = height *rows ;
316
322
}
317
323
}
318
-
324
+
319
325
Style s = parent .getStyle ();
320
326
return new Dimension (width + s .getHorizontalPadding (),
321
- height + s .getVerticalPadding ());
327
+ height + s .getVerticalPadding ());
322
328
}
323
329
324
330
/**
0 commit comments