i have made a frames ruler that i’d like to embed inside a JViewport. the default behavior of JViewport.add( rulerComponent ) seems to be to create a view whose size is set to the rulerComponents, and does not change. i tried to .setPrefferedSize(), etc. to no avail because i can’t query the rulerComponent for it’s size to perform the calculation myself ( java.awt.Dimension always returns 0, 0 whether i call in main(), or in the constructor of the view’s parent).
even if i could set the viewport’s size, that wouldn’t do me that much good because the layout manager of it’s parent seems to only respect entire dimensions, not just one. what i would like to create is a viewport that get’s it’s height from the component it contains (to remain static), and for it’s width to stretch to fit it’s parent container. is there a good way to accomplish this? do i have to override the views getPrefferedSize method? see illustration.
i don’t need code or anything, just an explanation of how to setup the viewport so it lays out as described.