0

I have this main window that extends a JFrame which flips a lot of different JPanel's, so I thought the CardLayout would be useful for this kind of behavior.

I've added two panes in the CardLayout, one pane is way bigger than the other, when I added both panes, the first one which is smaller was shown, while the second which is bigger wasn't(Good behavior), but it left a huge space below of the first pane.

I don't know how the size works on the CardLayout, but It doesn't respond to pack(), looks like it uses a specific algorithm to figure out the preferred size for the layout.

Anyone got an idea?

Patrick.SE
  • 4,444
  • 5
  • 34
  • 44

1 Answers1

3

CardLayout allows the GUI to pack() to the size of the largest card.

You might 'arrange white-space in a visually pleasing manner' for the smaller cards, and put the larger cards into scroll-panes.

The first pane is a login form

I'd show that in a JOptionPane (e.g. as shown here - screenshot below) or a modal JDialog.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • The first pane is a login form, while the second one contains 4 calendars and many fields, if I put the second pane in a scrollView will this set the maximum height to the smaller pane? – Patrick.SE May 31 '12 at 04:25
  • Hmm well, I think we could argue on how we could implement visually speaking, the login pane. I find it more appealing to have everything incorporated within the main window. Besides, I have multiple Panes and I find the CardLayout very useful to switch between different views. I haven't had the change to try the scroll bar, but I will have to do it before the end of the week so I will keep you updated. – Patrick.SE May 31 '12 at 05:51
  • 1
    Don't get me wrong, the other components might logically fit well in a single `CardLayout`. It is just that I'm most used to seeing ('the path of least surprise') a log-in in a separate (modal) pop-up. A web-app would be different - you'd tend to keep it all contained in the one page. – Andrew Thompson May 31 '12 at 05:56
  • @AndrewThompson: +1 Agree, but limiting [_modality_](http://en.wikipedia.org/wiki/Mode_%28computer_interface%29) is also a useful goal. [SquirrlSQL](http://squirrel-sql.sourceforge.net/) is an example. – trashgod May 31 '12 at 13:01
  • 1
    @trashgod I like quasimodes. No, wait ..that's Quasimodo I'm thinking of. :) Thanks for the links. – Andrew Thompson May 31 '12 at 13:15