0
我正在开发,其中用户根据用户在使用前需要有安装该软件的软件。创建和加入JToggleButton中的面板编程
当用户点击软件抛出一个JDialog并要求用户输入和软件存储输入的菜单项。这工作正常。接下来我有一个问题。我想要一个切换按钮(用户输入的文本作为其标签)在面板内。我尝试使用categoryPanel.add(C.getCategoryButton)
,但它没有奏效。请帮忙!提前致谢。
这里是我做了什么...... 我已经创建了一个扩展JToggleButton中
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.
}
谢谢你jmhage! 它的工作原理!但直到你去全屏:(任何想法,为什么发生这种情况? –
@DR可以提供您的主要方法是什么? – jmhage
的主要方法是这样的.. '公共静态无效的主要(字符串ARGS []){ 的java .awt.EventQueue.invokeLater(新的Runnable(){。 公共无效的run(){ 新的大型机()调用setVisible(真);} });} ' 构造... '公共大型机(){ 的initComponents();} ' 的的initComponents()过长 –