
Re: Layout problem when using JTextPane
Hello,
Thank you for your reply.
Quote:
One thing is that width 99% is never good
First of all, let me explain why I used the layout hint "w 99%": basically what I want is "w 100%", however "w 100%" has the following behavior (as illustrated in the attached image) which I don't want:
- I run my frame,
- I maximize it and hence the JTextPane increases in width and wrapping is adjusted accordingly,
- when I minimize back, the JTextPane preserves its width and wrapping is hence not modified, instead the horizontal scrollbar will appear.
The "w 99%" appears visually as a "w 100%" (since the 1% is hardly noticed), and gives the desired behavior: when I minimize back, the JTextPane shrinks back, and wrapping is adjusted accordingly.
To describe it again, the desired behavior is:
- the text component fills all the space available in its parent horizontally, and if not all text can fit in one line, the text should wrap vertically
- whenever there's more/less width available, wrapping should adjust accordingly
So far with my application constraints (i.e. the hierarchy of Swing components JFrame > rootPanel > scrollPane > panel > textPanel > JTextPane which I have to stick with) "w 99%" is giving me this behavior, but if this is not the best way to achieve it, please advise.
Quote:
in Swing one need to set wmin 0 or the Swing components derived from JTextComponent will modify its minimum width to the current width
As for the minimum width bug in Swing, yeah I'm familiar with that bug, but I don't see why it is relevant in my case. I'm saying this because here, say I initialize the width of my frame to 300: I DON'T have the problem: the text component sets its minimum width to the current width of 300, and hence I cannot shrink the width of my text component below 300. If I had that problem, then I would set wmin to 0 as you're suggesting.
My problem here, as I already described in my previous posts, is the extra height that appears under certain conditions:
- initially - depending on many variables (e.g. some initial panel dimensions, and text length do not reproduce the problem)
- when running in the AWT thread using SwingUtilities.invokeAndWait() as opposed to the main thread (any feedback on this?)
- if you maximize the frame in one shot, etc.
Thanks,
Shant