本文介绍了如何更改joptionpane的大小和字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以更改JOptionPane的字体和文本大小吗?我尝试了它,只有当我在那个特定的Java类上运行文件"时,它才起作用.如果启动整个项目,则不会更改字体.我只想更改一个特定的JOptionPane而不是全部.

Can you change the font and size of the text of a JOptionPane? I tried it and it works only if I "run file" on that specific java class. If you start the whole project it does not change the font. I only want to change only a specific JOptionPane not all of them.

这是代码:

 UIManager.put("OptionPane.messageFont", new FontUIResource(new Font(
          "Arial", Font.BOLD, 18)));
 JOptionPane.showMessageDialog(null,"MESSAGE","ERROR",JOptionPane.WARNING_MESSAGE);

推荐答案

这很容易. JOption窗格不仅接受字符串,还接受组件.因此,您可以创建一个标签集并设置其字体并将其用作消息.

It's really easy. JOption pane accepts not only strings but also components. So you can create a label set its font and use it as message.

JLabel label = new JLabel("MESSAGE");
label.setFont(new Font("Arial", Font.BOLD, 18));
JOptionPane.showMessageDialog(null,label,"ERROR",JOptionPane.WARNING_MESSAGE);

我不明白为什么以前没人回答这个问题

I don't understand why nobody answered this question before

这篇关于如何更改joptionpane的大小和字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 23:41