Change JSpinner Size (width) [duplicate]
Asked Answered
I

2

10

My problem: JSpinner is so skinny that I can only see the chars on the string in the last spot.

ex: "Hello" I only see 'o'.

I have a JPanel in a JFrame's BorderLayout.SOUTH

The JPanel's layout manager is the default which is - correct me if I'm misinformed - a FlowLayout manager.

also there's multiple components in the previously mentioned JPanel.

I've tried

RandomSpinner = new JSpinner(tempModel);
int w = RandomSpinner.getWidth();   int h = RandomSpinner.getHeight();
RandomSpinner.setSize(new Dimension(w * 2, h));
add(RandomSpinner);

this had no effect on the width of the JSpinner.

How should I change the width of my JSpinner or is this a FlowLayout issue?

thank you

Inimitable answered 7/8, 2014 at 17:47 Comment(4)
please share a minimal testable code for fast response.Controvert
FlowLayout should use the spinner's preferred size.Glomma
Possible duplicate.Glomma
@user3218114: Thank you for examining this critically; the accepted answer acknowledges the potential problem.Glomma
M
13

You can do it all in the following three steps:

// 1. Get the editor component of your spinner:
Component mySpinnerEditor = mySpinner.getEditor()
// 2. Get the text field of your spinner's editor:
JFormattedTextField jftf = ((JSpinner.DefaultEditor) mySpinnerEditor).getTextField();
// 3. Set a default size to the text field:
jftf.setColumns(your_desired_number_of_columns);
Mil answered 7/8, 2014 at 17:55 Comment(0)
W
0

Set the preferred and minimum sizes:

RandomSpinner = new JSpinner(tempModel);
int w = RandomSpinner.getWidth();   int h = RandomSpinner.getHeight();
Dimension d = new Dimension(w * 2, h);
RandomSpinner.setPreferredSize(d);
RandomSpinner.setMinimumSize(d);

Setting preferred size should be enough if you have enough space in your frame.

Wat answered 7/8, 2014 at 17:59 Comment(1)

© 2022 - 2024 — McMap. All rights reserved.