how to dynamicly add new button?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jx2
    New Member
    • Feb 2007
    • 228

    how to dynamicly add new button?

    Code:
    class myFrame{
    private javax.swing.JButton myb;
    
    void myFrame(){
            myb = new javax.swing.JButton();
            myb.setText("my text");
            myb.setBounds(0,0,100,100);
            myb.setVisible(true);
    }
    }
    looks allright but nothing happen WHY?
    and how to fix it?

    thx
    jx2
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by jx2
    Code:
    class myFrame{
    private javax.swing.JButton myb;
    
    void myFrame(){
            myb = new javax.swing.JButton();
            myb.setText("my text");
            myb.setBounds(0,0,100,100);
            myb.setVisible(true);
    }
    }
    looks allright but nothing happen WHY?
    and how to fix it?

    thx
    jx2
    You didn't add the button to the ContentPane of the JFrame. As a matter of fact,
    I don't see a JFrame at all, nor a Frame.

    kind regards,

    Jos

    Comment

    Working...