i'm trying to modify a java code. I have a jSpinner where the user have to choose a number like minimum 0 and after this step the user can continue by clicking the OK button and continue his steps...

So here what i want is when the user didn't enter any value in the jSpinner and if he clicks the OK button to continue, it must display "Error you must enter minimum value 1!" and stop to go to the next step. The user must stay in the same window.

For this what i tried is to create a piece of code like this:

public int getAlerte() {

     int x = 0;
        if (Integer.parseInt(jSpinnerParameter.getValue().toString()) <= -1 ||
            Integer.parseInt(jSpinnerParameter.getValue().toString()) >200) {
            JOptionPane.showMessageDialog(this, " ID number must be minimum 1",
                    "Alert", JOptionPane.ERROR_MESSAGE);
           x = 1; 
        }
        return x;  
}

I put this line in the starting of the code: import javax.swing.JOptionPane;

After this, when i enter -1 or nothing (initial value=0) it never display the error message.

Why the message is not displayed, could someone help please? i can't see the bug.

Thank you

Where are you calling the getAlerte method?

jLabelWithError.setVisible(true);
and to hide it again:
jLabelWithError.setVisible(false);

Right.As stultuske said:take one Jlabel and use setvisible(true / false) method for displaying your error msg that you want to print.

Genevish,
i call the getAlert methot at the end of the code.
Thank you

OK but where can i put the new jLabel?
I can't put it in same window of the jSpinner right.
Thx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.