2016-11-24 15 views
2

以下のコードでは、私は奇妙な問題を再現していました。私はシミュレータとデバイスの両方でテストしました&結果は同じです。私はコンテナ内に26個のボタンを持っています(そのレイアウトはflowlayoutです)。それ自体がBorderLayoutの南にあります(フォームのレイアウト)。しかしボタンの部分だけが見えます。次のコードで私は何を間違っていましたか? revalidateは何もしません。すべてのコンポーネントがBorderlayout.Southに表示されない

setLayout(new BorderLayout()); 

TextArea questionTextArea = new TextArea("1) question .........."); 
Container questionContainer = new Container(); 
questionContainer.add(questionTextArea); 

Container questionAnswerContainer = BoxLayout.encloseY(questionContainer); 
add(BorderLayout.CENTER, questionAnswerContainer); 

Container optionsContainer = new Container(new FlowLayout(Label.CENTER, Label.CENTER)); 
for (int i = 0; i < 26; i++) { 
    Button optionButton = new Button("i"); 
    optionsContainer.add(optionButton); 
} 
optionsContainer.revalidate(); 

Button skipButton = new Button("SKIP"); 
Container bottomContainer = BoxLayout.encloseY(optionsContainer, skipButton); 
bottomContainer.revalidate(); 
add(BorderLayout.SOUTH, bottomContainer); 
//f.revalidate(); 

ここでは7btnsのみが見られます。 skipButtonもそこにありません。他のボタンが表示されないのはなぜですか?

enter image description here

答えて

0

それはレイアウトを壊すかもしれないアプリを遅らせる以外にあまりとしてrevalidateを呼び出さないでください。これは、レイアウト全体が完了したときにのみ呼び出されるべきです。

FlowLayoutは、これらのケースでは一般的に薄片状であり、問​​題の原因です。幅があまりにも大きく、高さが小さすぎる場合は、希望の幅/高さを要求し、実際にコンテナに配置する場合は、必要なスペースが与えられません。これは、リフローなしで修正すると問題があり、パフォーマンスが大幅に低下します。

回避策は、自動配置でグリッドレイアウトのようなより決定論的なレイアウトを使用することです。

関連する問題