• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 532
  • Last Modified:

Modifying Look of JSpinner

I would like to modify the JSpinner so that the font is bigger and the up and down buttons are larger.
I would aslo like to make the JSpinner accept keyboard input. The Font statement I have below has no effect.

Does anyone know how to accomplish this?

private JSpinner secondsSpinner;
private SpinnerNumberModel secModel;

secondsSpinner = new javax.swing.JSpinner();

// Does not work
secondsSpinner.setFont(new java.awt.Font("Dialog", 1, 36));
ScriptPanel.add(secondsSpinner);
secondsSpinner.setBounds(760, 170, 160, 40);

secModel = new SpinnerNumberModel(1, 1, 3600, 1); //(value, min, max, step);
secondsSpinner.setModel(secModel);

0
GoldStrike
Asked:
GoldStrike
  • 8
  • 6
  • 5
1 Solution
 
sciuriwareCommented:
Just do:               UIManager.put("Spinner.font", <myfont>);
as soon as possible in your program.

;JOOP!
0
 
armoghanCommented:
How to attach key listner

JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) jSpinner1.getEditor();
JComponent textField = editor.getTextField();
textField.addKeyListener(new Frame1_jSpinner1_keyAdapter(this));




0
 
armoghanCommented:
You may be able to manupilate the buttons by doing. But not sure

((JButton)jSpinner1.getComponent(1))
((JButton)jSpinner1.getComponent(2))
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sciuriwareCommented:
I did it this way:

   JSpinner qlimit;
   SpinnerNumberModel qlimitModel;

      qlimitModel = new SpinnerNumberModel
      (
         Admin.threadQueueLimit,
         Admin.MINQUEUELIMIT,
         Admin.MAXQUEUELIMIT,
         1
      );
      qlimitModel.addChangeListener(this);
      qlimit = new JSpinner(qlimitModel);
// Wasting away the placement in a JPanel with JLabel etc.

   public void stateChanged(ChangeEvent e)
   {
   Object o = e.getSource();

      if(o == qlimitModel) // It's from the spinner!
      {
         .... = qlimitModel.getNumber().intValue();

;JOOP!
0
 
GoldStrikeAuthor Commented:
Just do:               UIManager.put("Spinner.font", <myfont>);
as soon as possible in your program.

OICSDisplay.java [386:1] illegal start of expression
        UIManager.put("secondsSpinner.font", <myfont>);
                                             ^
OICSDisplay.java [386:1] ')' expected
        UIManager.put("secondsSpinner.font", <myfont>);
                                                      ^
2 errors
Errors compiling OICSDisplay.
0
 
GoldStrikeAuthor Commented:
I did it this way:

Your code doesn't address any of my questions.
0
 
sciuriwareCommented:
You obviously can not even copy what I typed for you.
What the hell is secondSpinner.font ?

Now please create a font like:

   Font MyFont = new Font("Ms Sans Serif", Font.BOLD, 12);
    UIManager.put("Spinner.font", MyFont);

And do not add other things in it.
These 2 lines change the font inside all spinners in the whole application.

Did you try the other code? If it works fine for my customers, it will do for you.
;JOOP!
0
 
GoldStrikeAuthor Commented:
Can anyone point me to sample code where the JSpinner is modified?
0
 
GoldStrikeAuthor Commented:
sciurware
key - an Object specifying the retrieval key
Font MyFont = new Font("Ms Sans Serif", Font.BOLD, 12);
    UIManager.put("Spinner.font", MyFont);
Doesn't work, font int my spinner remains unchanged you must have short changed your customers :)

       // Spinner added to Script Panel
        secondsSpinner = new javax.swing.JSpinner();

        //secondsSpinner.setFont(new java.awt.Font("Dialog", 1, 48));
        ScriptPanel.add(secondsSpinner);
        secondsSpinner.setBounds(760, 170, 160, 40);
       
        Font myFont = new Font("Ms Sans Serif", Font.BOLD, 12);
        UIManager.put("Spinner.font", myFont);

        // Set Spinners in Script panel
        secModel = new SpinnerNumberModel(1, 1, 3600, 1); //(value, min, max, step);
        secondsSpinner.setModel(secModel);
       
0
 
armoghanCommented:
try applying the font of the FormatedtextField as I mentioned

JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) jSpinner1.getEditor();
JComponent textField = editor.getTextField();
textField.addKeyListener(new Frame1_jSpinner1_keyAdapter(this));
textField.setFont(new Font("Ms Sans Serif", Font.BOLD, 99));


This code works
But you have to try it
0
 
sciuriwareCommented:
You should apply UiManager calls BEFORE any component of that type is created!

And it is against the EE rules to provide you with a complete program.
You should understand the construct and apply it yourself.
;JOOP!
0
 
armoghanCommented:
The only problem with
 UIManager.put("Spinner.font", myFont);
is that it will be applied to all the Spinners, if you want to apply to a single spinner try the way i described above,
i.e. getting the TextField out and applying font on it
0
 
GoldStrikeAuthor Commented:
armoghan

textField.addKeyListener(new Frame1_jSpinner1_keyAdapter(this));

I don't quite understand what defines this "Frame1_jSpinner1_keyAdapter"

Can you explain what this does and how I define it.

thanks
0
 
sciuriwareCommented:
armoghan, I believe that you do want to have the same fonts in the same components.
If you apply different fonts everywhere your application will look like a Christmas tree
and your customers will not go to like it.

Just put yourself in their place with something like Word, Windows Explorer or whatever.

;JOOP!
0
 
armoghanCommented:
Actually

>>textField.addKeyListener(new Frame1_jSpinner1_keyAdapter(this));
is a key listener attached to textField to get the typed key.

    textField.addKeyListener(new KeyAdapter(){
      public void keyTyped(KeyEvent e) {
     System.out.println(""+e.getKeyChar());
   }


sciuriware
>>>>If you apply different fonts everywhere your application will look like a Christmas tree
Who knows one need to make a Christmas tree in Java :))

0
 
GoldStrikeAuthor Commented:
sciuware
     Font myFont = new Font("Ms Sans Serif", Font.BOLD, 12);
     UIManager.put("Spinner.font", myFont);

Can you explain how your code applies the font to the spinner. How does the UIManager know your talking about the
Spinner? I'm trying to understand the construct, this part does not make sense.

I'm applying your code in the constructor of my GUI class and the Spinner font does not change. I know I missing  a
step here somewhere and I think it has to do with the "key" in the UIManager.put statement.

thanks
0
 
sciuriwareCommented:
Can't you read?  "Spinner.font"  !!!!!
That's how JAVA works; you can control almost every kind of Component's properties.
This way, for instance, I told JAVA to make all buttons in Metal LOOK&FEEL to display as in MSWindows native mode.
From the above I see that you still can not follow instructions:

those lines must be applied BEFORE you are going to creat the components,
thus NOT in the constructor!!!!!
A place, to begin with, is directly in the main().
Later you can put things in a GUI-initialisation module.

;JOOP!
0
 
GoldStrikeAuthor Commented:
You have got to be kidding me, haven't you being reading the posting's, you need to look up the word "professional", I would rather not have sciuware's comments if he responds in such a rude and de-meaning way, he can keep his comments.

Go ahead an notify the admin, all they have to do is read the postings to realize you are way off base here.

There will be no apologies from me, none are needed, I responded accordingly.
0
 
GoldStrikeAuthor Commented:
I want to thank those who reponded in a "professional" manner.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 8
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now