這裏是我的問題:我試圖創建一個簡單的界面,我可以點擊幾個按鈕來調用differents函數,並在jlabel中顯示結果(總是文本)。我試圖讓2分隔部分(北/南或東/西)第一個區域將包含我所有按鈕的網格佈局或流佈局,第二個區域將顯示文本結果。Java Swing界面問題
這裏是我的聲明:
private static JButton b0 = new JButton("Creer Zone");
private static JButton b1 = new JButton("1");
private static JButton b2 = new JButton("2");
...
private static JButton b11= new JButton("11");
private static JButton b12 = new JButton("12");
private static JButton b14 = new JButton("Help");
private static JFrame windows = new JFrame();
private static JPanel container = new JPanel();
private static JLabel res = new JLabel();
,這裏是我他們如何加入到JFrame(這是真的awfull看):
container.add(b0);
container.add(b1);
container.add(b2);
...
container.add(b12);
container.add(b14);
container.add(res);
windows.setSize(450,500);
windows.setContentPane(container);
windows.setLocation(150 , 150);
windows.setVisible(true);
我試着聲明我的JPanel與一個網格佈局,borderlayout和改變位置(NSEW)和一個流程佈局,我總是結束與jlabel disapearing(這是壞的,因爲這個jlabel顯示我的功能的結果)
任何人都有一個簡單的方法來幫助我克服這個問題?非常感謝您採取任何時候
你不加入的面板(這看起來像它包含了一切)到JFrame。可能是一個問題...此外,我可以重現這個問題,原因是我沒有爲框架定義佈局。我通常使用FlowLayout來處理這樣的事情。如果你需要澄清,只需詢問。 :) – fireshadow52 2012-04-03 14:24:25
是否有一個特定的原因,你需要使用'JButton'來執行這些任務,正如你所提到的,或者其他任何東西都可以用來保存你的一天? :-) – 2012-04-03 15:15:42