我正在开发一个软件,用户必须在使用之前根据用户的需要设置软件。
当用户单击菜单项时,软件会抛出一个 JDialog 并要求用户输入,并且软件会存储输入。这工作正常。下一段我有问题。我想要一个面板内的切换按钮(用户输入的文本作为其标签)。我尝试使用categoryPanel.add(C.getCategoryButton)
但没有用。请帮忙!提前致谢。
这是我所做的......我创建了一个扩展 JToggleButton 的 Category 类
public class Category extends JToggleButton implements ActionListener
{
private JToggleButton categoryButton;
public JToggleButton getCategoryButton()
{
buildCategoryButton();
return categoryButton;
}
private void buildCategoryButton()
{
categoryButton = new JToggleButton();
categoryButton.setText(MainFrame.getUserInput());
categoryButton.setVisible(true);
}
这是调用 getCategoryButton() 方法的地方
private void catCapBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
userInput = catCapTextField.getText(); //works fine
Category C = new Category();
categoryPanel.add(C.getCategoryButton()); //doesn't work
validate();
catCapture.setVisible(false);//this closes the JDialog, and it works fine.
}