我正在使用NetBeans IDE來開發一個Swing應用程序,並且在一個JDialog窗口中,我試圖使用一些由netbeans添加的組件,還有一些組件動態地添加了組件,但是當我嘗試將組件添加到未顯示代碼中的initComponents。Netbeans initComponents正在竊聽代碼,該如何解決?
代碼:
public RegrasUsuarioDialog(java.awt.Frame parent, boolean modal) {
super(parent, "Preferências de conversão", modal);
//initComponents();
JRadioButton radioButton = new JRadioButton("Radio Button");
optionsPanel = new JPanel(new GridLayout(0, 1));
add(optionsPanel, BorderLayout.LINE_START);
optionsPanel.add(radioButton);
}
當我取消了的initComponents()方法,並發表意見:
optionsPanel = new JPanel(new GridLayout(0, 1));
add(optionsPanel, BorderLayout.LINE_START);
讓Netbeans的代碼創建它不工作的基本組件。
是使用'GroupLayout'的NetBeans? – MadProgrammer
閱讀並瞭解Java佈局管理器及其工作原理。這將幫助您學習如何在運行時向組件添加容器。 –
是的,NetBeans使用GroupLayout,我真的認爲這就是爲什麼我無法添加新組件,我將研究如何使用佈局管理器添加組件。謝謝。 –