我似乎無法將JButton添加到JPanel。 我有一個PropWindow(JFrame),它有一個PropView(JPanel)。 PropView-JPanel似乎被正確添加,因爲我可以使用paint()在其上繪製形狀。 但是,當我使用它來嘗試添加一個按鈕,它只是不會出現ATT所有:/JButton添加到JPanel不顯示
JButton testButton;
public PropView(int width, int height) {
super(true);
setLayout(null);
setSize(width, height);
//TestButton
testButton = new JButton("Test");
testButton.setLocation(10,10);
testButton.setSize(100, 50);
testButton.setVisible(true);
add(testButton);
setFocusable(true);
setVisible(true);
}
JFrame中和的JPanel均爲250x600像素。
在您的文章沒有顯示的理由爲自己的錯誤。我建議1)您考慮創建併發布[最小示例程序](http://stackoverflow.com/help/mcve)。 2)避免使用空白布局和像瘟疫一樣的絕對定位,因爲這會讓你陷入困境。 –
你試過把按鈕添加到'JFrame'嗎? – BitNinja
顯示你的油漆代碼,這可能會搞砸了,特別是如果你使用錯誤的油漆方法。 – NESPowerGlove