为所有组件Java设置相同的字体 [英] Set the same font for all component Java
问题描述
我想为 JPanel
中的所有组件设置一个特定的字体,但是我更喜欢这个问题更为普遍,不仅限于JPanel。如何将字体设置为容器中的组件列表(JFrame或JPanel)?
这是一个简单的方法,允许您指定Font到整个组件树下的任何容器(或者只是一个简单的组件,无所谓): 只要通过你的面板和具体的字体到这个方法,你会得到所有的孩子重构和。 I want to set a specific font for all component in a Here is a simple method that allows you to specify Font to the whole components tree under any Container (or just a simple Component, doesn't matter): Simply pass your panel and specific Font into this method and you will get all childs refactored aswell. 这篇关于为所有组件Java设置相同的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b $ pre $ public static void changeFont(Component component,Font font)
{
component.setFont(font); (子容器组件).getComponents())
{
changeFont(child,font)
if(component instanceof Container)
{
;
JPanel
but I prefer that the question is still more general and not limited to the JPanel. How can I set the font to a list of component in a container (JFrame or JPanel)? public static void changeFont ( Component component, Font font )
{
component.setFont ( font );
if ( component instanceof Container )
{
for ( Component child : ( ( Container ) component ).getComponents () )
{
changeFont ( child, font );
}
}
}