0

I have an undecorated JFrame which has a lot of components inside it (such as JSplitPanes, JPanels with GridBagLayouts, BoxLayouts, BorderLayouts etc). The code of building this JFrame is 2500 lines length, so I wouldn't place it here, or it's simpled version, sorry.

When I drag the JFrame by right or bottom side, it resizes OK, but when I drag it by left or top side, the components inside the JFrame are twitching a lot, so it looks very ugly.

My question is: Why does it happen? How can I prevent it (if I can)? Does anyone fix that in own practice?

UPD: I've written my own resizer for JFrame. It works OK for other windows, which have less amount of components.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
SeniorJD
  • 6,946
  • 4
  • 36
  • 53
  • 1
    please how is possible that `undecorated JFrame` can caused `JFrame by right or bottom side, it resizes OK` – mKorbel Jul 01 '13 at 13:22

1 Answers1

4

Resizing the frame implicitly validates the enclosed Container, which causes doLayout() to be invoked on the affected components each time the size changes. You can see a similar effect in repeated calls to paintComponent() when resizing this AnimationTest. As you observe, using thousands of components scales poorly. As an alternative, leverage the flyweight pattern to render only visible cells, as is done in JTable, JTree, JList, etc. If you can't use one of these, CellRendererPane, seen here, may help.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • How can apply *flyweight pattern* to `JSplitPane`? – SeniorJD Jul 02 '13 at 06:57
  • You'd also need to do implement editors, and you _may_ be able to work on just a subset of components; [profile](http://stackoverflow.com/q/2064427/230513) to be sure; note that `invalidate()`, "needs to execute quickly." – trashgod Jul 02 '13 at 10:10