Class inhertis from JButton, but button is not visible

Hi!
I'm having a class that inherits JButton. The idea was to give the button additional parameters, so it inherits from JButton to have all the attributes from JButton... But the problem is, that the Buttons are only visible when I touch them with the mouse. When I move the window they are invisible again...
Does anybody know why? Thanks for your help!
P.S Sorry for my bad english....

Okay, thanks for that hint!
Here is the class for the gui:
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class Temp extends JFrame{
     private static final long serialVersionUID = 5945597724189252185L;
     private JMenuItem closeItem = null;
     private JMenuItem newItem = null;
     private JPanel mainPanel = null;
     private JLabel startImage = null;
     private MineFieldButton[][] mines = null;
     public Temp(){
          this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          addMenu();
          this.add(getMainPanel());
          this.pack();
     private JPanel getMainPanel(){
          if (mainPanel == null){
               mainPanel = new JPanel();
               if (mines == null)
                    mainPanel.add(getStartImage());
               else{
                    mainPanel.setLayout(new GridBagLayout());
                    GridBagConstraints c = new GridBagConstraints();
                    c.fill = GridBagConstraints.HORIZONTAL;
                    c.ipady = 20;
                    c.ipadx = 20;
                    for (int x=0;x<mines.length;x++){
                         for (int y=0;y<mines[x].length;y++){
                              c.gridx = x;
                              c.gridy = y;
                              mainPanel.add(mines[x][y],c);
          return mainPanel;
     private JLabel getStartImage(){
          if(startImage == null){
               startImage = new JLabel();
          return startImage;
     private void addMenu(){
          JMenuBar menuBar = new JMenuBar();
          JMenu menu = new JMenu("File");
          menu.add(getNewItem());
          menu.add(getCloseItem());
          menuBar.add(menu);
          this.setJMenuBar(menuBar);
     private JMenuItem getNewItem(){
          if (newItem == null){
               newItem = new JMenuItem("New");
               newItem.addActionListener(new ActionListener(){
                    public void actionPerformed(ActionEvent e) {
                         createMines();
          return newItem;
     private JMenuItem getCloseItem(){
          if (closeItem == null){
               closeItem = new JMenuItem("Close");
               closeItem.addActionListener(new ActionListener(){
                    public void actionPerformed(ActionEvent e) {
                         System.exit(0);
          return closeItem;
     public void showGUI(){
          this.setVisible(true);
     private void createMines(){
          initMinesGUI();
          this.remove(getMainPanel());
          mainPanel = null;
          this.add(getMainPanel());
          this.pack();
     private void initMinesGUI(){
          mines  = new MineFieldButton[10][10];
          for (int x=0;x<mines.length;x++){
               for (int y=0;y<mines[x].length;y++){
                    mines[x][y] = new MineFieldButton();
                    mines[x][y].setBorder(BorderFactory.createRaisedBevelBorder());
                    mines[x][y].setX(x);
                    mines[x][y].setY(y);
                    mines[x][y].setNumber(x*y);
}And here for the class that inherits JButton "MineFieldButton":
import javax.swing.JButton;
public class MineFieldButton extends JButton{
     private static final long serialVersionUID = -1020769129018597011L;
     private int number = 0;
     private int x;
     private int y;
     public int getNumber() {
          return number;
     public void setNumber(int number) {
          this.number = number;
     public int getX() {
          return x;
     public void setX(int x) {
          this.x = x;
     public int getY() {
          return y;
     public void setY(int y) {
          this.y = y;
}I hope that you can find my error.... And that this is a SSCCE :-)
Thanks!

Similar Messages

Maybe you are looking for

  • Pages TOC lost when converting to ePub

    Being new to Pages, I viewed the online tutorials to get me started. I have managed to create a short book and the formatting of the text seems fine in Pages. However, when I export the file to ePub, and view this in iBooks on the iPad, the Table of

  • IOs7: iPod Touch 5. iMessage and Facetime not working.

    I just updated to ios7 and now imsg and facetime aren't working. It asks me for my Apple ID usename and password and then I get a message that says  "Could not sign in. Please check your network connection and try again." I am in wifi and internet is

  • How can we configure in MSS to view Employee work schedule?

    Hi, How can we configure in MSS to view Employee work schedule? Regards, Poornima

  • Where's the music?

    I just got the iPod Classic 80GB for Christmas... it was great for the first week or so. As i started to add more music, I noticed that some songs did not get put onto my iPod; this kept happening more and more. I then realized that when my iPod was

  • Family share approval keeps requesting icloud password

    I have Family Sharing set to require my approval when my daughter buys something from the store. Today when I try to approve items it keeps asking me to input my icloud password.  Sign In To Approve Enter the iCloud Apple ID password for [icloud emai