GridBagLayout on JPanel in JScrollPane
843805Nov 25 2005 — edited Nov 25 2005Howdy folks. I'm fairly new at this GUI programming thing. Let me try to explain what's happening without giving gobs of code, just to see if anyone recognizes it. If not, I'll post some code.
I have a DataSheetPanel that extends JPanel. It uses a GridBagLayout. The DataSheetPanel is in a JScrollPane, which in turn is in a tab of a JTabbedPane. I've written my own paintComponent method for the DataSheetPanel.
The bottom right component in the gridbag is a JTextArea. I've specified a fill of horizontal and a weightx of 1.0 so it gets all the extra horizontal space when the scroll pane is resized. When a resize occurs, I set the preferred size of the panel.
Everything works fine until I put some text in this bottom right text area so that it becomes long enough that the scroll pane needs a scroll bar. Then the scroll bar insists on positioning so I see the bottom of the panel. If I drag up the thumb, it just pops down to the bottom again. I cannot see the top of the panel. Does anyone recognize this problem?
I should mention that if I don't do all this in paintComponent, but instead just do it in a DataSheetPanel method that is called periodically, evenything works fine. The problem, of course, is that the bottom right text area doesn't get repainted dynamically when I resize the scroll pane, only when the method is called next time.
~~ Paul