2012-10-21 56 views
1
public class Primary extends JFrame { 
    public Primary(String title) { 
     super(title); 
     JLabel Label1 = new JLabel("hello"); 
     Container c= getContentPane(); 
     c.add(Label1, new AbsoluteConstraints(117,15)); 
    } 
} 

我已經寫了這段代碼,在主類中調用了runnable JFrame。 儘管沒有顯示錯誤,但在編譯時出現很多錯誤。 錯誤很長,但這裏是它的一個樣本:Java Swing錯誤= S AbsoluteConstraints

 
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: 
    cannot add to layout: constraint must be a string (or null) 
     at java.awt.BorderLayout.addLayoutComponent(BorderLayout.java:426) 
     at javax.swing.JRootPane$1.addLayoutComponent(JRootPane.java:531) 
     at java.awt.Container.addImpl(Container.java:1120)" 
+0

請學習java命名約定並堅持使用它們。 – kleopatra

回答

1

- 所有我想指出來的是BorderLayoutJFrame默認佈局第一。

-而你需要明確地改變Layout使用,如果你不想默認BorderLayout

-如果可能的話使用Group Layout通過NetBeans團隊早在2005年開發的,其根本真棒。使用Google現在免費提供的Windows Builder Pro工具。

2

的默認佈局管理爲JFrameBorderLayout

拿在JFrame API密切關注。

您需要更改佈局管理器,以滿足約束條件(或者反過來)的要求

+0

哦真棒。對不起,第一次使用GUI只是在練習。 – Jay

+0

你能告訴我怎麼去做這個嗎? – Jay

+0

對不起,正在用盡大門,請查看[使用佈局管理器](http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html) – MadProgrammer