Solved

Modifying Look of JSpinner

Posted on 2004-08-30
20
523 Views
Last Modified: 2008-03-10
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
Comment
Question by:GoldStrike
  • 8
  • 6
  • 5
20 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 11939068
Just do:               UIManager.put("Spinner.font", <myfont>);
as soon as possible in your program.

;JOOP!
0
 
LVL 18

Expert Comment

by:armoghan
ID: 11941919
How to attach key listner

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




0
 
LVL 18

Expert Comment

by:armoghan
ID: 11941983
You may be able to manupilate the buttons by doing. But not sure

((JButton)jSpinner1.getComponent(1))
((JButton)jSpinner1.getComponent(2))
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 24

Expert Comment

by:sciuriware
ID: 11949250
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
 

Author Comment

by:GoldStrike
ID: 11957233
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
 

Author Comment

by:GoldStrike
ID: 11957256
I did it this way:

Your code doesn't address any of my questions.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 11957982
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
 

Author Comment

by:GoldStrike
ID: 11958202
Can anyone point me to sample code where the JSpinner is modified?
0
 

Author Comment

by:GoldStrike
ID: 11958350
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
 
LVL 18

Expert Comment

by:armoghan
ID: 11959806
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 11960544
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
 
LVL 18

Expert Comment

by:armoghan
ID: 11960620
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
 

Author Comment

by:GoldStrike
ID: 11964485
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 11966102
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
 
LVL 18

Accepted Solution

by:
armoghan earned 250 total points
ID: 11970760
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
 

Author Comment

by:GoldStrike
ID: 11975074
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 11975409
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
 

Author Comment

by:GoldStrike
ID: 11986883
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
 

Author Comment

by:GoldStrike
ID: 11986888
I want to thank those who reponded in a "professional" manner.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 56
oracle 11g 23 106
Tomcat: Unable to run tomcat service. 2 23
java mysql insert application 14 27
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question