Discussion:
Line Break in FlowLayout of Panel
(zu alt für eine Antwort)
Nadine
2004-01-06 19:13:50 UTC
Permalink
Hi there,

the following problem occurred to me:

1)
I have a scrollPane and within that a Panel with several components
(Choice, TextField, CheckBox, ...).
It all works fine, except for the fact that it puts all of the
components in one row.
I just want to have 2 components in each row...

I tried the GridLayout, as it should fill the rows from left to right
first; instead it fills the columns first.

The problem is, that the number of components that can show up is
flexible and is calculated dynamically.

Part of the code:
[...]
panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 20));
//panel1.setLayout(new GridLayout(2 ,4, 20, 20));

[...]
panel1.add((java.awt.Component)o[i++]);
panel1.add((java.awt.Component)o[i]);

[...]
scrollPane1.add(panel1);
scrollPane1.getVAdjustable().setUnitIncrement(1);
scrollPane1.getHAdjustable().setUnitIncrement(1);
panel4.add(scrollPane1);
scrollPane1.setBounds(250, 100, 750, 95);
pack();


2)
Is there a possiblity to color the items of a List when a specific
event takes place?
Joachim Karrer
2004-01-07 07:04:07 UTC
Permalink
Post by Nadine
Hi there,
1)
I have a scrollPane and within that a Panel with several components
(Choice, TextField, CheckBox, ...).
It all works fine, except for the fact that it puts all of the
components in one row.
... as far as it has room to do so.
Post by Nadine
I just want to have 2 components in each row...
I tried the GridLayout, as it should fill the rows from left to right
first; instead it fills the columns first.
Standardbehaviour of Gridlayout. Just resort your insertions...
Post by Nadine
The problem is, that the number of components that can show up is
flexible and is calculated dynamically.
... or use GridBagLayout (First Component with GridBagConstraints.width=1,
second Component will require
GridBagConstraints.width=GridBagConstraints.REMAINDER)
Post by Nadine
2)
Is there a possiblity to color the items of a List when a specific
event takes place?
Are you talking about AWT or Swing?

With AWT: No.
With Swing: Sure. Just make yourself confident with ListCellRenderers.

Have a nice day
Joachim

BTW: this is a German group. Preferably most people here like to read
articles in German.
Michael Holtermann
2004-01-07 09:21:44 UTC
Permalink
Post by Joachim Karrer
... or use GridBagLayout
Or, much better, use FormLayout (www.jgoodies.com). The GridBagLayout is a
perfect possibility to be confused by your own code...

Greets, Michael.

Loading...