public void CreateButton() { PicButton = new JButton(); add(PicButton); setLayout(new BorderLayout()); PicButton.setName("PicButton"); setAutoscrolls(true); PicButton.setIcon(new ImageIcon("/resource/blank.jpg")); PicButton.setHorizontalAlignment(2); PicButton.setMargin(new Insets(0, 0, 0, 0)); PicButton.setVerticalAlignment(1); PicButton.setVerticalTextPosition(1); PicButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { PicButtonActionPerformed(evt); } }); int num = getComponentCount(); String stuff = getComponent(0).getName(); }