0

I really doesn't understand what it's going on with my JSpinner. I instanciated it and then I tried to set it on my JPanel with a setBounds but the only thing I get is this :

JSpinner

The little square on the middle is what should be my JSpinner..

My code is like this :

private JSpinner spinnerDayBirth;
spinnerDayBirth = new JSpinner();
spinnerDayBirth.setBounds(280,351, 25, 25);
add(spinnerDayBirth);

They're few lines betweens each of these instructions but they never touch to this JSpinner.

So I wonder why I can't get a normal JSpinner.. Thank you in advance !

MHogge
  • 5,408
  • 15
  • 61
  • 104
  • 2
    Don't use setBounds (and by extension, null layouts). Consider providing a runnable example that demonstrates your problem – MadProgrammer May 12 '14 at 22:14
  • First thing said in the [official null layout tutorial](http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html) "don't use null layout". – DSquare May 12 '14 at 22:32
  • 1
    Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson May 12 '14 at 23:08
  • 1) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete and Verifiable Example). 2) Provide ASCII art (or an image with a simple drawing) of the GUI as it should appear in smallest size and (if resizable) with extra width/height. – Andrew Thompson May 12 '14 at 23:09
  • Try to remove the line `spinnerDayBirth.setBounds(280,351, 25, 25);`. – user1803551 May 13 '14 at 01:23
  • I did know that null layout wasn't good to use and I didn't had a lot of time to make what I wanted but I didn't know it will cause me such issues.. Thank's for your advices ! :) – MHogge May 13 '14 at 20:34

1 Answers1

0

I had same problem. I worked with simply spinnerModel then I tried your program and it works too. There is one thing to do - re-set your model. If you want the spinner to appear you have to set new spinner model again.

for example i typed this code:

    public void method() {
       jPanel2.setLocation(0, 96);
       jPanel2.setSize(getWidth(), getHeight() - 96);
       jPanel2.getHeight() - jButton1.getHeight() - 50);
       jSpinner1.setModel(new SpinnerNumberModel(2,1,10,1));   //<- this is line you need to type
       jSpinner1.setSize(60, 25);
       jSpinner1.setLocation(0,0);
}