怎样更改 JSpinner的字体大小

Gere Yeung 2010-09-01 09:50:54
为什么我不能用 UImanager 更改 JSpinner 的字体大小?

Font defaultFont = new Font("宋体", Font.PLAIN, 20);
UIManager.put("JSpinner.font", defaultFont);

字体大小不变。
直接用setFont也不行

Font defaultFont = new Font("宋体", Font.PLAIN, 20);
UIManager.put("JSpinner.font", defaultFont);
spinner.setFont(defaultFont);
...全文
119 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
huntor 2010-09-01
  • 打赏
  • 举报
回复
JTextField可以改变,JSpinner就不行。我在网上找到下面这个例子
import java.awt.*;
import javax.swing.*;

public class SpinnerSize
{
public SpinnerSize()
{
String[] suits = { "spades", "diamonds", "clubs", "hearts" };
SpinnerListModel suitModel = new SpinnerListModel(suits);
JSpinner suitSpinner = new JSpinner(suitModel);

// set the preferred size
Dimension d = suitSpinner.getPreferredSize();
d.width = 100;
suitSpinner.setPreferredSize(d);

// modify the JTextField appearance
JSpinner.ListEditor editor = new JSpinner.ListEditor(suitSpinner);
JTextField tf = editor.getTextField();
tf.setHorizontalAlignment(JTextField.CENTER);
tf.setFont(new Font("lucida sans regular", Font.PLAIN, 16));
suitSpinner.setEditor(editor);

JPanel panel = new JPanel();
panel.add(suitSpinner);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(panel);
f.setSize(300,100);
f.setLocation(200,200);
f.setVisible(true);
}

public static void main(String[] args)
{
new SpinnerSize();
}
}
Gere Yeung 2010-09-01
  • 打赏
  • 举报
回复
UIManager.put("Spinner.font", defaultFont)
也不起作用啊,Mr Hunter.
huntor 2010-09-01
  • 打赏
  • 举报
回复
没有前面那个J
huntor 2010-09-01
  • 打赏
  • 举报
回复
UIManager.put("Spinner.font", defaultFont);

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧