GoldStrike
asked on
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(secondsSpi nner);
secondsSpinner.setBounds(7 60, 170, 160, 40);
secModel = new SpinnerNumberModel(1, 1, 3600, 1); //(value, min, max, step);
secondsSpinner.setModel(se cModel);
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
ScriptPanel.add(secondsSpi
secondsSpinner.setBounds(7
secModel = new SpinnerNumberModel(1, 1, 3600, 1); //(value, min, max, step);
secondsSpinner.setModel(se
How to attach key listner
JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) jSpinner1.getEditor();
JComponent textField = editor.getTextField();
textField.addKeyListener(n ew Frame1_jSpinner1_keyAdapte r(this));
JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) jSpinner1.getEditor();
JComponent textField = editor.getTextField();
textField.addKeyListener(n
You may be able to manupilate the buttons by doing. But not sure
((JButton)jSpinner1.getCom ponent(1))
((JButton)jSpinner1.getCom ponent(2))
((JButton)jSpinner1.getCom
((JButton)jSpinner1.getCom
I did it this way:
JSpinner qlimit;
SpinnerNumberModel qlimitModel;
qlimitModel = new SpinnerNumberModel
(
Admin.threadQueueLimit,
Admin.MINQUEUELIMIT,
Admin.MAXQUEUELIMIT,
1
);
qlimitModel.addChangeListe ner(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().in tValue();
;JOOP!
JSpinner qlimit;
SpinnerNumberModel qlimitModel;
qlimitModel = new SpinnerNumberModel
(
Admin.threadQueueLimit,
Admin.MINQUEUELIMIT,
Admin.MAXQUEUELIMIT,
1
);
qlimitModel.addChangeListe
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().in
;JOOP!
ASKER
Just do: UIManager.put("Spinner.fon t", <myfont>);
as soon as possible in your program.
OICSDisplay.java [386:1] illegal start of expression
UIManager.put("secondsSpin ner.font", <myfont>);
^
OICSDisplay.java [386:1] ')' expected
UIManager.put("secondsSpin ner.font", <myfont>);
^
2 errors
Errors compiling OICSDisplay.
as soon as possible in your program.
OICSDisplay.java [386:1] illegal start of expression
UIManager.put("secondsSpin
^
OICSDisplay.java [386:1] ')' expected
UIManager.put("secondsSpin
^
2 errors
Errors compiling OICSDisplay.
ASKER
I did it this way:
Your code doesn't address any of my questions.
Your code doesn't address any of my questions.
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.fon t", 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!
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.fon
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!
ASKER
Can anyone point me to sample code where the JSpinner is modified?
ASKER
sciurware
key - an Object specifying the retrieval key
Font MyFont = new Font("Ms Sans Serif", Font.BOLD, 12);
UIManager.put("Spinner.fon t", 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(n ew java.awt.Font("Dialog", 1, 48));
ScriptPanel.add(secondsSpi nner);
secondsSpinner.setBounds(7 60, 170, 160, 40);
Font myFont = new Font("Ms Sans Serif", Font.BOLD, 12);
UIManager.put("Spinner.fon t", myFont);
// Set Spinners in Script panel
secModel = new SpinnerNumberModel(1, 1, 3600, 1); //(value, min, max, step);
secondsSpinner.setModel(se cModel);
key - an Object specifying the retrieval key
Font MyFont = new Font("Ms Sans Serif", Font.BOLD, 12);
UIManager.put("Spinner.fon
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(n
ScriptPanel.add(secondsSpi
secondsSpinner.setBounds(7
Font myFont = new Font("Ms Sans Serif", Font.BOLD, 12);
UIManager.put("Spinner.fon
// Set Spinners in Script panel
secModel = new SpinnerNumberModel(1, 1, 3600, 1); //(value, min, max, step);
secondsSpinner.setModel(se
try applying the font of the FormatedtextField as I mentioned
JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) jSpinner1.getEditor();
JComponent textField = editor.getTextField();
textField.addKeyListener(n ew Frame1_jSpinner1_keyAdapte r(this));
textField.setFont(new Font("Ms Sans Serif", Font.BOLD, 99));
This code works
But you have to try it
JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) jSpinner1.getEditor();
JComponent textField = editor.getTextField();
textField.addKeyListener(n
textField.setFont(new Font("Ms Sans Serif", Font.BOLD, 99));
This code works
But you have to try it
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!
And it is against the EE rules to provide you with a complete program.
You should understand the construct and apply it yourself.
;JOOP!
The only problem with
UIManager.put("Spinner.fon t", 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
UIManager.put("Spinner.fon
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
ASKER
armoghan
textField.addKeyListener(n ew Frame1_jSpinner1_keyAdapte r(this));
I don't quite understand what defines this "Frame1_jSpinner1_keyAdapt er"
Can you explain what this does and how I define it.
thanks
textField.addKeyListener(n
I don't quite understand what defines this "Frame1_jSpinner1_keyAdapt
Can you explain what this does and how I define it.
thanks
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sciuware
Font myFont = new Font("Ms Sans Serif", Font.BOLD, 12);
UIManager.put("Spinner.fon t", 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
Font myFont = new Font("Ms Sans Serif", Font.BOLD, 12);
UIManager.put("Spinner.fon
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
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!
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!
ASKER
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.
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.
ASKER
I want to thank those who reponded in a "professional" manner.
as soon as possible in your program.
;JOOP!