T
Thomas Richter
Hi folks,
the problem at hand is how to align individual components that are part
of a JComboBox.
The JComboBox uses a custom Renderer to render its contents, and each
content consists of two strings of variable size, arranged in a JPanel.
The getListCellRendererComponent() of the renderer now returns the
JPanel containing the two components.
So far, so good. This works.
The problem is that the sizes of the two components differ througout the
items of the JComboBox, which means that the elements within the JList
in the JCombobox (or rather, its JList rendering the non-editable items)
are not aligned to each other. Of course they can't, they are individual
JPanels each with its own layout manager, and thus do not know anything
on each other.
Needless to say, this looks visually very unattractive.
So what can I do about this? I have a JComboBox with a very complex
layout and the requirement that each entry necessarily is a pair of data
types of various sizes. How can I make the elements be aware of each
other and have a common layout for all of them?
Illustration:
+----------------------------------------------+
| foofoo | barbarbarbarbarbarbarbar |
+----------------------------------------------+
| foofoofoofoofoofoofoo | bar |
+----------------------------------------------+
This is how the JComboBox currently renders. But I want it
laid out such that the separator between the two elements forming one
entry of it are underneath each other.
Any ideas?
Greetings,
Thomas
the problem at hand is how to align individual components that are part
of a JComboBox.
The JComboBox uses a custom Renderer to render its contents, and each
content consists of two strings of variable size, arranged in a JPanel.
The getListCellRendererComponent() of the renderer now returns the
JPanel containing the two components.
So far, so good. This works.
The problem is that the sizes of the two components differ througout the
items of the JComboBox, which means that the elements within the JList
in the JCombobox (or rather, its JList rendering the non-editable items)
are not aligned to each other. Of course they can't, they are individual
JPanels each with its own layout manager, and thus do not know anything
on each other.
Needless to say, this looks visually very unattractive.
So what can I do about this? I have a JComboBox with a very complex
layout and the requirement that each entry necessarily is a pair of data
types of various sizes. How can I make the elements be aware of each
other and have a common layout for all of them?
Illustration:
+----------------------------------------------+
| foofoo | barbarbarbarbarbarbarbar |
+----------------------------------------------+
| foofoofoofoofoofoofoo | bar |
+----------------------------------------------+
This is how the JComboBox currently renders. But I want it
laid out such that the separator between the two elements forming one
entry of it are underneath each other.
Any ideas?
Greetings,
Thomas