ScrollPane Flow Layout
Hi Guys,
I am at my wits end as to how I can solve this. I really can't find a solution, I hope you can help.
I have a gui layout thus:
JTabbedPane -> JScrollPane -> JPanel -> JPanel (instead of awt.canvas)
I have multiple java2d 'graphs' that I wish to layout on this scrollpane left to right which then wrap. If the screen is full, vertical scrollbars are triggered. So I think flow layout is the closest to this as I really must maintain the original component size. Grid layout etc resize the graphs making it look wrong.
The problem is that with flow layout, it scrolls infinitely horizontally. The only way I can get to to stop scrolling harizontally is by calling setPreferedSize(). When I do this however it seems to disable the scroll bars.
I have tried all combinations of layout managers to try and give me the same effect - to no avail. I have tried setting the scrollpane display policies and again this has no effect.
So I suppose I can see two possibilites:
1- find some way of getting the scrollpane to wrap without setPreferredSize()
2- find a way of getting the scroll bars working, with setPreferredSize()
My code, looks like this:
scrollPaneContents_ = new JPanel();
scrollPaneContents_.setPreferredSize(new Dimension(scrollPane_.getWidth(),scrollPane_.getHeight()));
scrollPaneContents_.setLayout(new FlowLayout(FlowLayout.CENTER));
scrollPane_ = new JScrollPane(scrollPaneContents_);
//scrollPane_ = new JScrollPane(scrollPaneContents_/*,
//scrollPane_.VERTICAL_SCROLLBAR_AS_NEEDED,scrollPane_.HORIZONTAL_SCROLLBAR_NEVER*/);
//layout.setConstraints(scrollPane_, layoutConstraints);
// I want it to scroll to the width less and continue downwards forever
scrollPaneContents_.setVisible(true);
tabView_.add("Tab Name",scrollPane_);
tabView_.refresh();
view_.refresh();
scrollPaneContents_.add(graphView_);
As you can see I have commented some out to try every combination :)
Any suggestions?
TIA

