Post by chriscrawford on May 20, 2016 12:37:28 GMT -8
I am trying to get a scrolling panel into my window. This should all be very simple. There's complete documentation on the Java website explaining how it's done. Unfortunately, I can't use their code in my program, for a variety of reasons. But what the hey, it can't be that hard, can it?
Right.
So I set up a class "HistoryBookPanel" that extends JScrollPane. I insert an instantiation of that class into my main window. My main window is a JFrame containing just two Components: DialogPanel (an extension of a JPanel with its own paintComponent() method), and HistoryBookPanel. The main window has a horizontal box layout, so the the DialogPanel is on the left and the HistoryBookPanel is on the right. They are both the same height, but the DialogPanel is about 900 pixels wide while the HistoryBookPanel is about 450 pixels wide.
The two panels each have their own paintComponent() methods. Each one works as designed -- with one exception: after HistoryBookPanel is painted, it is immediately overwritten with solid white. Somebody, somewhere, is overwriting the panel. Who could it be? I go through endless tedious tests, commenting out all sorts of different lines of code, and nothing can stop the overwriting. It's certainly not DialogPanel doing the overwriting.
I eventually figure out that I'm drawing the imagery into HistoryBookPanel, but HistoryBookPanel incorporates a "viewport" that contains the actual graphics being displayed. So I draw into the viewport instead. No effect. I set up a custom class that extends the Viewport and has its own paintComponent() method that overrides the existing one. That changes nothing. I try another round of random variations; nothing works.
Time to give up.
Right.
So I set up a class "HistoryBookPanel" that extends JScrollPane. I insert an instantiation of that class into my main window. My main window is a JFrame containing just two Components: DialogPanel (an extension of a JPanel with its own paintComponent() method), and HistoryBookPanel. The main window has a horizontal box layout, so the the DialogPanel is on the left and the HistoryBookPanel is on the right. They are both the same height, but the DialogPanel is about 900 pixels wide while the HistoryBookPanel is about 450 pixels wide.
The two panels each have their own paintComponent() methods. Each one works as designed -- with one exception: after HistoryBookPanel is painted, it is immediately overwritten with solid white. Somebody, somewhere, is overwriting the panel. Who could it be? I go through endless tedious tests, commenting out all sorts of different lines of code, and nothing can stop the overwriting. It's certainly not DialogPanel doing the overwriting.
I eventually figure out that I'm drawing the imagery into HistoryBookPanel, but HistoryBookPanel incorporates a "viewport" that contains the actual graphics being displayed. So I draw into the viewport instead. No effect. I set up a custom class that extends the Viewport and has its own paintComponent() method that overrides the existing one. That changes nothing. I try another round of random variations; nothing works.
Time to give up.