我的问题是: JSpinner太瘦了,我只能看到字符串最后一处的字符。
例如:"Hello“我只看到”o“。
我在JFrame的BorderLayout.SOUTH中有一个JPanel
JPanel的布局管理器是默认的,它是一个FlowLayout管理器--如果我被误导了,请纠正我。
此外,在前面提到的JPanel中还有多个组件。
我试过了
RandomSpinner = new JSpinner(tempModel);
int w = RandomSpinner.getWidth(); int h = RandomSpinner.getHeight();
RandomSpinner.setSize(new Dimension(w * 2, h));
add(RandomSpinner);这对JSpinner的宽度没有影响。
我应该如何更改我的JSpinner的宽度,或者这是一个FlowLayout问题?
谢谢
发布于 2014-08-08 01:55:17
您可以通过以下三个步骤完成所有操作:
// 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);发布于 2014-08-08 01:59:44
设置首选大小和最小大小:
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);如果帧中有足够的空间,设置首选大小就足够了。
https://stackoverflow.com/questions/25188926
复制相似问题