This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm fairly new to this LayoutManager stuff, and its driving me nuts. This should be easy enough.
I want to arrange rectangular components side-by-side. The width of each component is the same, and remains fixed. The number of rectangular components (and therefore the total width) will vary dynamically.
I want to do this inside a scroll-pane. When there's lots of them, they will go off the edge, resulting in a horizontal scroll-bar (not flowing). When there's only a few, they should be left justified, still butting up against each other, with space on the right.
Simple enough right? But no matter which layout manager I try, it always does some centering, and spaces them out, instead of keeping them up against each other. Very frustrating.
Hello Steven Bell , I have visited jgoodies.com, i have downlaoded Freeware like FormDemo but how can we use this, b/c i am new to this and i need your help please. I run java start web but the form asking some size but there is no button like submit ......
Thanks for your help everyone. I think I've cracked it, in a roundabout sort of way. As always, the solution has raised new problems, which I'm slowly puzzling through.
GridLayout (as Rachel suggested) and also BoxLayout seemed to fit the bill, but the problem I was having with both of these, was that they seemed to be spacing my components out horizontally, but...
...actually I was confusing myself. The components are JPanels, which in turn contain JButton component. I forgot to set the width on the JPanels, and so they were expanding themselves to take up the available space, while the JButtons (visible) were fixed width. Hence the annoying horizontal centered spacing effect, was resolved by setting the widths. Is there a way to tell a JPanel to choose the smallest possible width? (contract around my JButton, rather than expanding to the layout grid cell width). Currently I've told the JPanel's preffered width to equal to the JButton's preferred width, but it seems to want to make a few pixels of padding, which I dont want. Is there a container padding setting?
The other problem was with verticle centering. I fixed this by putting all my components within another JPanel, then telling the outer panel to be FlowLayout(FlowLayout.LEFT), so that the inner panel was placed in the top left (easier/better way of doing that?)