Solved

Modifying Look of JSpinner

Posted on 2004-08-30
20
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

615 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