JScrollPane>Always finding this difficult to work with

I am always finding difficult to work with JScrollPane. I have a JDialog popping up when i click a button. In the JDialog, i would like to have a JScorllPane which has two fields. Field type and its corresponding name. There are a lot of these pairs which change dynamically. Field type should be on the left side and name should be on the right side. Initially i was not using scrollPanes. I was simply adding them to the contentPane of JDialog by creating JLabels and setting their bounds. The portion alotted for them is restricted.

Now, i have to use a ScrollPane to which i have to add these components. I tried to directly add the components to the scrollPane instead of adding to the conentPane. Not a single one is viewable. I tried using validate(). No use. I tried adding the components to a JPanel and adding that to the ScrollPane. No use. Can any one tell me a solution to do this? Even a generalized one is useful. If anyone has already implemented anything with ScrollPanes like adding some Labels to it or adding some Panels, that would be great too.

[1080 byte] By [Java_Newa] at [2007-10-2 10:42:20]
# 1
> Can any one tell me a solution to do this?Start by posting a sample program that demonstrates the problem,explaining what you expect it to do.just a frame, a button, an actionListener to popup a dialog.the dialog with a scrollpane and multiple labels.
Michael_Dunna at 2007-7-13 2:51:08 > top of Java-index,Desktop,Core GUI APIs...
# 2

Create a Panel using FlowLayout. Create two labels and specify their size. Add them to this panel. This is your one pair. And then add all the pairs while you are looping through, to another JPanel which uses BoxLayout. Then, add this Panel to a JScrollPane. After that, use setViewPortView method to set the ViewPort of the actual Panel you want to view in the ScrollPane. Hope it works.

Gopi_Ua at 2007-7-13 2:51:08 > top of Java-index,Desktop,Core GUI APIs...
# 3
Yes, this is what i am exactly looking for. Thanks in advance. I will try it.
Java_Newa at 2007-7-13 2:51:08 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thanks, it worked out finally.
Java_Newa at 2007-7-13 2:51:08 > top of Java-index,Desktop,Core GUI APIs...