Slightly Off Topic: Trouble forcing component size...?
Hi,
Apologies if this is slightly off topic but here we go:
I have a JFrame with with a tabbedpane inside it. One tab has a JPanel
containing 4 JScrollPanes each of which has a JEditorPane inside - see
image1.jpg.
On first loading the app the 4 JEditorPanes are each perfectly stretched to
fill an even space on the panel. But for some reason when I import a large
amount of text into any of them - using jpanel.setText(large amount of text)
the editor stretches out pushing all of the second row of items down - see
image2.jpg. I expected the JEditorPane to gain scrollbars and not resize
when filling up with text?
Any ideas on how to enforce the same size for the JEditorPanes but add
scrollbars when needed would be happily recieved? I have set the scrollbars
policy of the underlying JScrollPanes to 'As Needed' and this has no
effect - sometimes scrollbars are added but the pane is still expanded
pushing everything else aside?
Thanks
Scott
Attachment(s):
image1.JPG
image2.JPG
请先登录再写评论。
Hi Scott,
Set the minimum and preferred size to the scrollpanes.
Tom
Scott Curtis wrote:
Tom,
I had considered this but I didn't know what size to set them to as the user
can stretch the screen and I wanted them to always fill the panel like they
do in the first image - I assumed setting a specific size would mean they
stay that size no matter whether the app is maximized or stretched to
whatever size.
I set the min and preferred sizes to 0 instead of the default (in IDEA gui
designer) of -1 and this appears to have solved the problem? Is this because
size of 0 tells the component to maximize itself within it's own cell of the
Panel - somehow?
Thanks
Scott
"Thomas Singer (MoTJ)" <nomail@nodomain.com> wrote in message
news:cjrdbk$adj$1@is.intellij.net...
>
>
>
>
to
large
text)
see
scrollbars
No. A component has 4 sizes, a minimum size, a preferred size, a maximum
size and a the (actual) size. The first 3 sizes are used by the layout
manager to set the last one. If you set the scrollpanes' minimum and
preferred size to - let's say - (with = 200, height = 150), the layout
manager of the panel, which contains the scrollpanes, will take the
preferred size to calculate the initial size. If the panel is resized,
the layout manager takes the minimum and maximum sizes.
I don't know, never used the IDEA-GUI-designer for more than a
5-minutes-test. I suggest you to use plain code to achive the things you
like, because in this case you will learn how it works under the hood.
Tom
Scott Curtis wrote:
>>Hi Scott,
>>
>>Set the minimum and preferred size to the scrollpanes.
>>
>>Tom
>>
>>
>>Scott Curtis wrote:
>>
>>>Hi,
>>>
>>>Apologies if this is slightly off topic but here we go:
>>>
>>>I have a JFrame with with a tabbedpane inside it. One tab has a JPanel
>>>containing 4 JScrollPanes each of which has a JEditorPane inside - see
>>>image1.jpg.
>>>
>>>On first loading the app the 4 JEditorPanes are each perfectly stretched
>>>fill an even space on the panel. But for some reason when I import a
>>>amount of text into any of them - using jpanel.setText(large amount of
>>>the editor stretches out pushing all of the second row of items down -
>>>image2.jpg. I expected the JEditorPane to gain scrollbars and not resize
>>>when filling up with text?
>>>
>>>Any ideas on how to enforce the same size for the JEditorPanes but add
>>>scrollbars when needed would be happily recieved? I have set the
>>>policy of the underlying JScrollPanes to 'As Needed' and this has no
>>>effect - sometimes scrollbars are added but the pane is still expanded
>>>pushing everything else aside?
>>>
>>>Thanks
>>>Scott
>>>
>>>
Yeah I try to wherever possible to code by hand (usually I have to because
the designer is so basic), but for the more repetitive tasks I turn to the
designer.
Thanks for the explanation. I didn't realise that's how it worked.
- scott
"Thomas Singer (MoTJ)" <nomail@nodomain.com> wrote in message
news:cjrnrj$2cv$1@is.intellij.net...
>
>
gui
because
the
>
>
>
>
user
they
they
gui
because
the
stretched
resize