Sun's layout managers are all sh**. Welcome to the painful world of "we wrote crap in 1997 and even now we still can't be bothered to fix it".
Quote:Original post by vovansim
Soooo. What I am doing now is essentially using a big JList of categories and each category is a JList of pieces of data. It almost works, but not quite. The problem is that if I give the list of categories VERTICAL layout orientation, then the above example looks like this:
The problem is that Sun's layout managers were written by a lazy person.
Instead of doing a useful, intelligent algorithm that would require some effrot by the coder, they just went for the "I can't be bothered, I'll do the simplest thing that doesn't work but which I could sort of almost pretend works".
What happens is that a lot of layout managaers ask for the minimum size of a PARTICULAR dimension (note: not in the "I'm a moron who works at sun and doesn't know the meaning of the word dimension" sense, but in the "english has this word that's been around for centuries" sense), and ignores everything else.
So, a borderlayout will ask the NORTH component "what's your minimum height?", and provide ONLY that.
Unofruntately, Sun's OWN WIDGETS are implemented so that for different current widths they return *DIFFERENT* minimum heights, and when the layout asks they *ASSUME* they can have as much widht as they want.
So, they return the min height, get it, and then disappear of the edge of the screeen. This is broken in every version of java 1.2, 1.3, 1.4 (and, I've heard, 5, although I haven't tried it there yet).
I'm 99% sure you're getting the same problem with your final layout: the layout manager is asking "what's your minimum possible width?" and the third item is giving an honest answer: if it's *FORCED* to, it can go that narrow.
You have two solutions:
1. Get pissed off with Sun and write your own layout managers from scratch, using your BRAIN. This is annoying, hard work, and shouldn't be necessary :(.
2. override the methods in your components for getMinSize, getPrefSize, getMaxSize and intelligently calculate the actual sizes given the current situations.
Number 2 will, usually, require hacking around with your other classes in a very very non-OOP way which is ugly and hard to maintain, because the idiots desining layout managers were too stupid to understand what *minimal amount of information* you need to do layout properly. Hint: when asked "how big are you?" you need to be given some information about how big the asker would LIKE you to be. This is well known, it's been around for many years, but apparently was too complex for the sun staff to comprehend...Sob.
I've done both methods in the past. Both work. The second method is horrible to maintain and gives you headaches fixing bugs in.The first method is easy to maintain but you can never use the sun layout managers again, and you have to write the whole layout system from scratch. I'm meaning to open-source some of my laout managers some day, but not soon - I just don't have enough time to clean them up, document them, etc :(.