problems with program - cards show up only when I minimize/resize window

I'm making 1 program with poker cards. I got 2 problems:

1. When I click JButton "generate" nothing happens but when I click minimize of the program window or just click on the edge of the window cards show up.

2. When I click "generate" again program doesn't generate new cards.

I've been using same code for ActionListener like I used with another program when I was making simple calculator and there was everything fine. Also around words of "generate" button there is rectangle and on calculator buttons there was no rectangle.

Here is my main class ("generate" button in code is "Generiraj random karte"):

Any time you add/remove components from a container you should call revalidate() on the container (if it derives from JComponent) and then repaint(). The first call tells the layout managers to layout the components present and the second tells the container to repaint itself and its children (and borders). Since you're adding to the JFrame, you're actually adding to its contentPane which is a Container variable but is almost always a JPanel. So to fix this, call

Java Code:

// after adding new components onto okvir...
((JPanel)okvir.getContentPane()).revalidate(); // cast it to a JPanel so we can call revalidate
okvir.repaint();

Also, I added code tags to your post to help the code retain its formatting. To see how to do this yourself for your next posts, please see the link in my signature below.

Sry, from your messaging I wrongly understood that you wrote JPanel wrong and that it should go JFrame... but anyway I tried both but for JPanel I get message: "JPanel cannot be resolved to a type".

Have you imported the JPanel class? You should probably read up on importing classes and other Java basics before trying to tackle Swing as you may be trying to run before you can walk. You can find out more on it here: Creating and Using Packages

Problem is that I don't get information which line makes problem. Althought I get this message work is saved...

Are you sure about this? That would be a very unusual NullPointerException message if it didn't give you the line numbers that are involved. If still having a problem, post the actual exception message lines here.

Have you imported the JPanel class? You should probably read up on importing classes and other Java basics before trying to tackle Swing as you may be trying to run before you can walk. You can find out more on it here: Creating and Using Packages

I didn't import JPanel... I don't have much time for learning, I have to be done soon and practicly everything is working except this 2 problems.

Originally Posted by Fubarable

Are you sure about this? That would be a very unusual NullPointerException message if it didn't give you the line numbers that are involved. If still having a problem, post the actual exception message lines here.

Fixed this. Problem was in class where I had comparator and made wrong compare...

btw. I tried with repaint only but only change when I click "generate" is that now back of the cards is removed but I still need to click on the edge of the window for cards to show up.