Scrollable JTextAreas, and my aching head.
Ultimately what I want is to have multiple seperately scrollable JTextAreas size-by-side in my JFrame. I figured this would be terribly simple, and yet I'm very confused.
My scrollable JScrollPane/JTextArea won't appear if I put it in a WEST or EAST cell of a BorderLayout, nor will it appear at all in a GridBagLayout or FlowLayout.
This code works to get one scrollable JTextArea. But if I do anything creative to try to add in a second one, none of them appear. What is my head missing?
class ScrollFrame extends JFrame
Container cont = getContentPane();
jTextAreaA = new JTextArea();
jScrollPaneA = new JScrollPane(jTextAreaA);
Fpr borderlayout this will (try to) give 180 px width in east & west or 300 px height in north or south.
For gridbag it depends on other constraints.
Aw, man! I swear I tried that!
Oh, well! Apparently I didn't, because this time it worked. Thanks.
OK, so...I did that. And to some extent it works. I've even got two JScrollPane/JTextArea combination working side by side.
However, in order to get them to resize and reposition correctly when the JFrame is resized, I have had to register with the JFrame as a ComponentListener and explicitly call setPreferredSize, setSize, and setLocation. I would like the LayoutManager to be handling all of this. Is there an easier/better way to do this?
Is there perhaps a way to get the LayoutManager to come back through and reposition after I've changed their preferredSize?
I was having trouble finding the right 'hook' within the whole Container/JFrame functionality that would allow me to set the preferredSize (and size/location) of my multiple scrollable JTextArea objects, at the right time, and in a way that didn't interfere with anything else. Then after a good night's sleep it came to me...
It took about 60 seconds to extend the FlowLayout class and cut-and-paste my size/location code into the layoutContainer(Container) method, before calling super.layoutContainer. Bingo. It worked first time, every time.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center