1

I am creating simple application in java - Eclipse - WindowBuilder Editor. JFrame`s contentPane has JGoodies FormLayout in which I have to place 3 or 4 Panels - depending on mode.

It is proper way to make if construction that decides if content pane will be divided 1x3 or 1x4(facilitation because between all I use relatedgaps and so on..)?

I am not sure if this is good approach but I do not know how can I do this in other way than if construction. It has to be practical and flexible approach - to handle resizing the window, et cetera..

mKorbel
  • 109,525
  • 20
  • 134
  • 319
bez
  • 93
  • 9
  • 2
    Java is not JavaScript. Developing a Swing application is not the same as developing a browser application. Use an appropriate Swing layout manager, like GridBagLayout, and it won't matter whether you have 3 JPanels or 4 JPanels. Oh, using a window builder for Swing creates more problems than it solves. – Gilbert Le Blanc Mar 04 '14 at 23:11

1 Answers1

3

Common approaches for dynamic layout include these:

  • Use revalidate(), and possibly repaint(), to layout a Container again after adding or removing components, as shown here.

  • Replace the layout and validate() the Container, as shown here.

  • Use CardLayout to replace one panel with another, as shown here and here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045