Wrapped components not visible with FlowLayout

T

Tassilo Horn

Hi all,

I have a JPanel using BorderLayout. On the SOUTH I add another JPanel
containing buttons and a text field using FlowLayout. When I shrink the
JFrame, the components in the latter JPanel wrap around as it should be,
but the components in the second row are not visible. I can only see a
very small part of their top.

What's wrong here?

Here's the code:

--8<---------------cut here---------------start------------->8---
public MapFrame(AnnotatedOsmGraph graph) {
super("jgStreetMap");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

getContentPane().setLayout(new BorderLayout());
resultPanel = new ResultPanel();
mapPanel = new MapPanel(graph, resultPanel);
getContentPane().add(mapPanel, BorderLayout.CENTER);
getContentPane().add(resultPanel, BorderLayout.EAST);

JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
getContentPane().add(buttonPanel, BorderLayout.WEST);

JPanel detailPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
getContentPane().add(detailPanel, BorderLayout.SOUTH);

detailPanel.add(new JLabel("Visible details:"));

showMapButton = new JCheckBox("Map", mapPanel.isShowingMap());
detailPanel.add(showMapButton);
showMapButton.addChangeListener(new ChangeListener() {
[...]
});

showNatureButton = new JCheckBox("Streets only", mapPanel
.isShowingStreetsOnly());
detailPanel.add(showNatureButton);
showNatureButton.addChangeListener(new ChangeListener() {
[...]
});

searchTextField = new JTextField(20);
searchTextField.setToolTipText("Enter a name of a town and hit return.");
detailPanel.add(searchTextField);
searchTextField.addActionListener(new ActionListener() {
[...]
});

[...]

pack();
setVisible(true);
validate();
}
--8<---------------cut here---------------end--------------->8---

Is there something obvious?

Bye,
Tassilo
 
T

Tassilo Horn

Tassilo Horn said:
I have a JPanel using BorderLayout. On the SOUTH I add another JPanel
containing buttons and a text field using FlowLayout. When I shrink
the JFrame, the components in the latter JPanel wrap around as it
should be, but the components in the second row are not visible. I
can only see a very small part of their top.

I observed the inner panels preferred size, and it doesn't change when
components wrap around into the next row. Is that expected? If yes,
then FlowLayout is only meaningful inside components with a size big
enough for new rows, right?

In the meantime, I packed the panel into a JScrollPane, so that I can at
least access the buttons that would wrap around in a FlowLayout.

Bye,
Tassilo
 
M

markspace

Tassilo said:
Hi all,

I have a JPanel using BorderLayout. On the SOUTH I add another JPanel
containing buttons and a text field using FlowLayout. When I shrink the
JFrame, the components in the latter JPanel wrap around as it should be,
but the components in the second row are not visible. I can only see a
very small part of their top.

What's wrong here?


Reading the documentation, I see this:

"The components are laid out according to their preferred sizes and the
constraints of the container's size. The NORTH and SOUTH components may
be stretched horizontally; the EAST and WEST components may be stretched
vertically; the CENTER component may stretch both horizontally and
vertically to fill any space left over. "


So it looks like SOUTH doesn't stretch vertically to accommodate when
your flow layout changes height.

I'm not sure how NORTH and SOUTH determine their initial height, however.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top