一个字体在IntelliJ的选择字体对话框中没有出现。

4
我使用这个代码安装了Monaco字体。但是,在设置 -> 编辑器 -> 颜色和字体 -> 字体中没有出现。我该怎么办?
5个回答

6

您需要在目录/usr/share/fonts/truetype/中创建一个名为monaco的文件夹,并将字体文件monaco.ttf复制到该文件夹中。

然后运行命令fc-cache -v -f


2
尝试以另一种方式安装字体。只需使用字体查看器即可。

enter image description here

我在 ElementaryOS 下使用 IDEA,它对我很有效。
更新:

enter image description here


字体查看器显示 Monaco 已安装。 - Incerteza
2
@Alex 在 设置 -> 编辑器 -> 颜色和字体 -> 字体 选项中,必须禁用 仅显示等宽字体。请查看更新。 - Anton Dozortsev
1
字体在IntelliJ的选择对话框中没有出现!这不清楚吗? - Incerteza
@Alex 尝试寻找另一个版本的TTF文件 - Anton Dozortsev

1
在IntelliJ设置中,您只能更改编辑器窗格的字体。但是,您可以将系统中可用的任何字体设置为任何IntelliJ UI组件。如果您想控制整个IDE(项目树、菜单栏、标签等),请创建一个简单的插件,并在其中添加以下代码行:UIManager.put("XXX.font", new Font("fontName", style, size)) 其中XXX是UI组件的名称,如Label、TextField、Tree等。您可以在这里找到Swing组件的完整列表(IntelliJ使用Swing框架构建):Java Swing UI属性列表? 执行插件后,所有新的字体设置都将应用于IntelliJ的UI。以下是代码示例:
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;

import javax.swing.*;
import java.awt.*;

public class MyUIPlugin implements ToolWindowFactory
{

    private ToolWindow myToolWindow;

    public static final String TOOL_WINDOW_ID = "MyUISettings";

    public MyUIPlugin() {}

    // Create the tool window content.
    public void createToolWindowContent(final Project project, final ToolWindow toolWindow) {
        myToolWindow = toolWindow;
        this.createContent(toolWindow);
}

public void createContent(final ToolWindow toolWindow) {
    final ContentFactory contentFactory = toolWindow.getContentManager().getFactory();
    JLabel myPluginUI = new JLabel("This is empty panel with my custom fonts settings behind it");
    final Content content = contentFactory.createContent(myPluginUI, "", true);
    toolWindow.getContentManager().addContent(content);
    UIManager.put("TextField.font", new Font(...));
    UIManager.put("List.font", new Font(...));
    UIManager.put("Label.font", new Font(...));
    UIManager.put("Button.font", new Font(...));
    .....
    SwingUtilities.updateComponentTreeUI(myPluginUI);
}

}

此外,您甚至可以编写小的Swing代码,而不是使用JLabel占位符,通过调用GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()获取UI元素列表和系统中所有可用字体的列表。并且您可以在插件窗口中为不同的组件类型分配不同的字体,并完全自定义IntelliJ UI字体。

1
我最近也遇到了类似的问题。IntelliJ IDEA找不到字体的原因可能是字体安装位置不正确。
一开始,我的字体放在~/.fonts下,在IDEA设置中没有显示字体名称。然后我把字体的副本放在.local/share/fonts下,并使用命令fc-cache -v -f刷新缓存,这样在IDEA字体设置中就可以选择字体名称了。
希望这会对你有所帮助。

enter image description here


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接