posted 19 years ago
I have a JScrollPane in which I want to display a number of rows. Each row must have the same height and of a size that will not change (e.g., 20 pixels). Each row will have the same width and of a size that will be variable throughout the use of the application.
I have a frame that uses a BorderLayout and places the scroll pane in the CENTER. I want the size of the scroll pane to be as big as the CENTER can be.
Now to my problems. At some times given the number of rows and the height each should be, it does not add up to the height of the scroll pane's viewport. In this case, I'm finding it ignores the height of the row and spreads the rows out. At other times given the same thiing, it adds up to more than the height of the scroll pane's viewport. In this case, I'm finding it again ignores the height and packs them together. Basically, when the screen is drawn initially, the scroll pane does what it can do to "fit" my data in its window (expanding or shrinking it). I do not want this. What I need is to retain the number of rows and their height and width regardless of the size of the scroll pane which should be dependent on the size of its container.
I've tried all the different layout managers, nested panels, setting preferred sizes, etc. and all combinations to find nothing works. I'm assuming that since my experience is minimal I am just doing something wrong but I cannot figure out what. I would greatly appreciate any tips or guidance to point me down the right path. Below I've outlined my "current" set of nested widgets I'm trying to use.
container.setLayout(new BorderLayout());
container.add(new MyTopPanel(), BorderLayout.NORTH);
container.add(new MyBottomScrollPane(), BorderLayout.CENTER);
MyBottomScrollPane - extends JScrollPane
setViewportView(new MyScrollPaneContent());
MyScrollPaneContent - extends JPanel
setLayout(???); // I need a bunch of rows
for (int i = 0; i < 10; i++) {
add(new MyRowContent());
}
MyRowContent - extends Canvas
width = calculated
height = always 21 pixels
Many, MANY thanks to any who can help!