Setting Font

18 views
Skip to first unread message

Bryan J Buchanan

unread,
Sep 15, 2020, 10:36:00 PM9/15/20
to lanterna-discuss
Using Tutorial01 code, I tried to set fonts, but it doesn't seem to do anything. Is the code below correct ?

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            Font[] allFonts = ge.getAllFonts();
            ArrayList<Font> fonts = new ArrayList<>();
            
            for (int i = 0; i < allFonts.length; i++) {
                if (allFonts[i].getName().contains("Ubuntu Mono")) fonts.add(allFonts[i]);
            }
            for (int i = 0; i < fonts.size(); i++) {
                fonts.set(i, fonts.get(i).deriveFont(48.0f));
                System.err.println(fonts.get(i).toString());
            }
            AWTTerminalFontConfiguration config = AWTTerminalFontConfiguration.newInstance(fonts.toArray(new Font[0]));
            defaultTerminalFactory.setTerminalEmulatorTitle​("A window title");
            defaultTerminalFactory.setTerminalEmulatorFontConfiguration(config);
            terminal = defaultTerminalFactory.createTerminal();

Bryan J Buchanan

unread,
Sep 16, 2020, 8:31:19 PM9/16/20
to lanterna-discuss
Solved. Needed SwingTerminalFontConfiguration instead of AWTTerminalFontConfiguration

           /**
             * get fonts from system
             */

            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            Font[] allFonts = ge.getAllFonts();
            ArrayList<Font> fonts = new ArrayList<>();
            for (int i = 0; i < allFonts.length; i++) {
                if (allFonts[i].getName().contains("Ubuntu Mono")) {
                    fonts.add(allFonts[i]);
                }
            }
            /**
             * resize
             */

            for (int i = 0; i < fonts.size(); i++) {
                fonts.set(i, fonts.get(i).deriveFont(42.0f));
                System.err.println(fonts.get(i).toString());
                System.err.println(getFontWidth(fonts.get(i)));
                System.err.println(getFontHeight(fonts.get(i)));
            }

            defaultTerminalFactory.setTerminalEmulatorTitle​("This is a title");
            defaultTerminalFactory.setInitialTerminalSize(new TerminalSize(80, 25));
            defaultTerminalFactory.setPreferTerminalEmulator(true);
            SwingTerminalFontConfiguration config = SwingTerminalFontConfiguration.newInstance(fonts.toArray(new Font[0]));
            defaultTerminalFactory.setTerminalEmulatorFontConfiguration(config);
            terminal = defaultTerminalFactory.createTerminal();

Reply all
Reply to author
Forward
0 new messages