Total members 11890 |It is currently Sat Apr 20, 2024 2:56 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





I have a group of JCheckBoxes, which I add to a JPanel
checkBoxPanel, which is itself added to a JPanel panel. The
LayoutManager of checkBoxPanel is set to FlowLayout, with the
expectation that the check boxes are arranged in lines, starting a new
line whenever a line does not have enough space left for the next
check box. This works well if the parent of checkBox Panel (which is
panel) itself is FlowLayout. But if panel is set to GridBagLayout, all
check boxes are placed in one line, even if there is not enough space,
pushing some check boxes partially or completely out of the drawn
area. I don't understand how the check box panel's layout manager's
decision whether or not to start a new line depends on the layout
manager of its parent container. Any advice? Thanks!




Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time

Whenever you nest containers and choose a layout manager that allows it
to think for itself, you open yourself up to this behavior. If a child
container does not have a fixed size, then it can change size to fit its
components. The parent container may accommodate this change, or it may
not -- which may force the child container to rearrange its components.

The interaction here is not simple nor is there a definitive rule for
how it works. It is what it is. If precise positioning is crucial, use a
GridBagLayout and make sure you place lots of constraints so it does not
try to think for itself.

Computers thinking is dangerous: that is what gave us the apocalypse. It
is best if we think for them.

_________________
Please recommend my post if you found it helpful


Author:
Proficient
User avatar Posts: 228
Have thanks: 0 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Layout with Nested JPanels
 containers use a border Layout as their default layout     -  
 Frame with Null Layout- set layout NULL     -  
 Nested function     -  
 Break in Nested Loops     -  
 nested ordered list     -  
 Nested classes(inner class) in java     -  
 specify a container's layout     -  
 BoxLayout usage example - Box-Layout     -  
 FlowLayout with window-Buttons Layout Example     -  
 Window-Frame-with Diagonal Layout     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com